You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/2014/2014-toc/sql-server-transaction-locking-and-row-versioning-guide.md
+34-35Lines changed: 34 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -225,7 +225,7 @@ GO
225
225
226
226
A phantom read is a situation that occurs when two identical queries are executed and the collection of rows returned by the second query is different. The example below shows how this may occur. Assume the two transactions below are executing at the same time. The two SELECT statements in the first transaction may return different results because the INSERT statement in the second transaction changes the data used by both.
227
227
228
-
```
228
+
```sql
229
229
--Transaction 1
230
230
BEGIN TRAN;
231
231
SELECT ID FROMdbo.employee
@@ -234,10 +234,9 @@ GO
234
234
SELECT ID FROMdbo.employee
235
235
WHERE ID >5and ID <10;
236
236
COMMIT;
237
-
238
237
```
239
238
240
-
```
239
+
```sql
241
240
--Transaction 2
242
241
BEGIN TRAN;
243
242
INSERT INTO dbo.employee
@@ -566,7 +565,7 @@ GO
566
565
567
566
To ensure a range scan query is serializable, the same query should return the same results each time it is executed within the same transaction. New rows must not be inserted within the range scan query by other transactions; otherwise, these become phantom inserts. For example, the following query uses the table and index in the previous illustration:
568
567
569
-
```
568
+
```sql
570
569
SELECT name
571
570
FROM mytable
572
571
WHERE name BETWEEN 'A' AND 'C';
@@ -581,7 +580,7 @@ SELECT name
581
580
582
581
If a query within a transaction attempts to select a row that does not exist, issuing the query at a later point within the same transaction has to return the same result. No other transaction can be allowed to insert that nonexistent row. For example, given this query:
583
582
584
-
```
583
+
```sql
585
584
SELECT name
586
585
FROM mytable
587
586
WHERE name = 'Bill';
@@ -593,7 +592,7 @@ SELECT name
593
592
594
593
When deleting a value within a transaction, the range the value falls into does not have to be locked for the duration of the transaction performing the delete operation. Locking the deleted key value until the end of the transaction is sufficient to maintain serializability. For example, given this DELETE statement:
595
594
596
-
```
595
+
```sql
597
596
DELETE mytable
598
597
WHERE name = 'Bob';
599
598
```
@@ -606,7 +605,7 @@ DELETE mytable
606
605
607
606
When inserting a value within a transaction, the range the value falls into does not have to be locked for the duration of the transaction performing the insert operation. Locking the inserted key value until the end of the transaction is sufficient to maintain serializability. For example, given this INSERT statement:
608
607
609
-
```
608
+
```sql
610
609
INSERT mytable VALUES ('Dan');
611
610
```
612
611
@@ -970,7 +969,7 @@ deadlock-list
970
969
971
970
These [!INCLUDE[tsql](../includes/tsql-md.md)] statements create test objects that are used in the examples that follow.
972
971
973
-
```
972
+
```sql
974
973
-- Create a test table.
975
974
CREATE TABLE TestTable
976
975
(col1 int);
@@ -992,7 +991,7 @@ GO
992
991
993
992
A `SELECT` statement is executed under a transaction. Because of the `HOLDLOCK` lock hint, this statement will acquire and retain an Intent shared (IS) lock on the table (for this illustration, row and page locks are ignored). The IS lock will be acquired only on the partition assigned to the transaction. For this example, it is assumed that the IS lock is acquired on partition ID 7.
994
993
995
-
```
994
+
```sql
996
995
-- Start a transaction.
997
996
BEGIN TRANSACTION
998
997
-- This SELECT statement will acquire an IS lock on the table.
@@ -1005,7 +1004,7 @@ BEGIN TRANSACTION
1005
1004
1006
1005
A transaction is started, and the `SELECT` statement running under this transaction will acquire and retain a shared (S) lock on the table. The S lock will be acquired on all partitions which results in multiple table locks, one for each partition. For example, on a 16-cpu system, 16 S locks will be issued across lock partition IDs 0-15. Because the S lock is compatible with the IS lock being held on partition ID 7 by the transaction in session 1, there is no blocking between transactions.
1007
1006
1008
-
```
1007
+
```sql
1009
1008
BEGIN TRANSACTION
1010
1009
SELECT col1
1011
1010
FROM TestTable
@@ -1016,7 +1015,7 @@ BEGIN TRANSACTION
1016
1015
1017
1016
The following `SELECT` statement is executed under the transaction that is still active under session 1. Because of the exclusive (X) table lock hint, the transaction will attempt to acquire an X lock on the table. However, the S lock that is being held by the transaction in session 2 will block the X lock at partition ID 0.
1018
1017
1019
-
```
1018
+
```sql
1020
1019
SELECT col1
1021
1020
FROM TestTable
1022
1021
WITH (TABLOCKX);
@@ -1028,7 +1027,7 @@ SELECT col1
1028
1027
1029
1028
A `SELECT` statement is executed under a transaction. Because of the `HOLDLOCK` lock hint, this statement will acquire and retain an Intent shared (IS) lock on the table (for this illustration, row and page locks are ignored). The IS lock will be acquired only on the partition assigned to the transaction. For this example, it is assumed that the IS lock is acquired on partition ID 6.
1030
1029
1031
-
```
1030
+
```sql
1032
1031
-- Start a transaction.
1033
1032
BEGIN TRANSACTION
1034
1033
-- This SELECT statement will acquire an IS lock on the table.
@@ -1043,7 +1042,7 @@ BEGIN TRANSACTION
1043
1042
1044
1043
On partition IDs 7-15 that the X lock has not yet reached, other transactions can continue to acquire locks.
1045
1044
1046
-
```
1045
+
```sql
1047
1046
BEGIN TRANSACTION
1048
1047
SELECT col1
1049
1048
FROM TestTable
@@ -1308,7 +1307,7 @@ BEGIN TRANSACTION
1308
1307
1309
1308
On session 1:
1310
1309
1311
-
```
1310
+
```sql
1312
1311
USE AdventureWorks2012; -- Or the 2008 or 2008R2 version of the AdventureWorks database.
1313
1312
GO
1314
1313
@@ -1331,7 +1330,7 @@ BEGIN TRANSACTION;
1331
1330
1332
1331
On session 2:
1333
1332
1334
-
```
1333
+
```sql
1335
1334
USE AdventureWorks2012;
1336
1335
GO
1337
1336
@@ -1353,7 +1352,7 @@ BEGIN TRANSACTION;
1353
1352
1354
1353
On session 1:
1355
1354
1356
-
```
1355
+
```sql
1357
1356
-- Reissue the SELECT statement - this shows
1358
1357
-- the employee having 48 vacation hours. The
1359
1358
-- snapshot transaction is still reading data from
@@ -1365,7 +1364,7 @@ BEGIN TRANSACTION;
1365
1364
1366
1365
On session 2:
1367
1366
1368
-
```
1367
+
```sql
1369
1368
-- Commit the transaction; this commits the data
1370
1369
-- modification.
1371
1370
COMMIT TRANSACTION;
@@ -1374,7 +1373,7 @@ GO
1374
1373
1375
1374
On session 1:
1376
1375
1377
-
```
1376
+
```sql
1378
1377
-- Reissue the SELECT statement - this still
1379
1378
-- shows the employee having 48 vacation hours
1380
1379
-- even after the other transaction has committed
@@ -1409,7 +1408,7 @@ GO
1409
1408
1410
1409
On session 1:
1411
1410
1412
-
```
1411
+
```sql
1413
1412
USE AdventureWorks2012; -- Or any earlier version of the AdventureWorks database.
1414
1413
GO
1415
1414
@@ -1436,7 +1435,7 @@ BEGIN TRANSACTION;
1436
1435
1437
1436
On session 2:
1438
1437
1439
-
```
1438
+
```sql
1440
1439
USE AdventureWorks2012;
1441
1440
GO
1442
1441
@@ -1459,7 +1458,7 @@ BEGIN TRANSACTION;
1459
1458
1460
1459
On session 1:
1461
1460
1462
-
```
1461
+
```sql
1463
1462
-- Reissue the SELECT statement - this still shows
1464
1463
-- the employee having 48 vacation hours. The
1465
1464
-- read-committed transaction is still reading data
@@ -1473,7 +1472,7 @@ BEGIN TRANSACTION;
1473
1472
1474
1473
On session 2:
1475
1474
1476
-
```
1475
+
```sql
1477
1476
-- Commit the transaction.
1478
1477
COMMIT TRANSACTION;
1479
1478
GO
@@ -1482,7 +1481,7 @@ GO
1482
1481
1483
1482
On session 1:
1484
1483
1485
-
```
1484
+
```sql
1486
1485
-- Reissue the SELECT statement which now shows the
1487
1486
-- employee having 40 vacation hours. Being
1488
1487
-- read-committed, this transaction is reading the
@@ -1512,7 +1511,7 @@ GO
1512
1511
1513
1512
The following [!INCLUDE[tsql](../includes/tsql-md.md)] statement enables READ_COMMITTED_SNAPSHOT:
1514
1513
1515
-
```
1514
+
```sql
1516
1515
ALTERDATABASE AdventureWorks2012
1517
1516
SET READ_COMMITTED_SNAPSHOT ON;
1518
1517
```
@@ -1521,7 +1520,7 @@ ALTER DATABASE AdventureWorks2012
1521
1520
1522
1521
The following [!INCLUDE[tsql](../includes/tsql-md.md)] statement will enable ALLOW_SNAPSHOT_ISOLATION:
1523
1522
1524
-
```
1523
+
```sql
1525
1524
ALTERDATABASE AdventureWorks2012
1526
1525
SET ALLOW_SNAPSHOT_ISOLATION ON;
1527
1526
```
@@ -1551,7 +1550,7 @@ ALTER DATABASE AdventureWorks2012
1551
1550
1552
1551
- Read-committed that uses row versioning by setting the `READ_COMMITTED_SNAPSHOT` database option to `ON` as shown in the following code example:
1553
1552
1554
-
```
1553
+
```sql
1555
1554
ALTERDATABASE AdventureWorks2012
1556
1555
SET READ_COMMITTED_SNAPSHOT ON;
1557
1556
```
@@ -1560,14 +1559,14 @@ ALTER DATABASE AdventureWorks2012
1560
1559
1561
1560
- Snapshot isolation by setting the `ALLOW_SNAPSHOT_ISOLATION` database option to `ON`as shown in the following code example:
1562
1561
1563
-
```
1562
+
```sql
1564
1563
ALTER DATABASE AdventureWorks2012
1565
1564
SET ALLOW_SNAPSHOT_ISOLATION ON;
1566
1565
```
1567
1566
1568
1567
A transaction running under snapshot isolation can access tables in the database that have been enabled for snapshot. To access tables that have not been enabled for snapshot, the isolation level must be changed. For example, the following code example shows a `SELECT` statement that joins two tables while running under a snapshot transaction. One table belongs to a database in which snapshot isolation is not enabled. When the `SELECT` statement runs under snapshot isolation, it fails to execute successfully.
1569
1568
1570
-
```
1569
+
```sql
1571
1570
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
1572
1571
BEGIN TRAN
1573
1572
SELECT t1.col5, t2.col5
@@ -1578,7 +1577,7 @@ ALTER DATABASE AdventureWorks2012
1578
1577
1579
1578
The following code example shows the same `SELECT` statement that has been modified to change the transaction isolation level to read-committed. Because of this change, the `SELECT` statement executes successfully.
1580
1579
1581
-
```
1580
+
```sql
1582
1581
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
1583
1582
BEGIN TRAN
1584
1583
SELECT t1.col5, t2.col5
@@ -1612,7 +1611,7 @@ ALTER DATABASE AdventureWorks2012
1612
1611
1613
1612
For example, a database administrator executes the following `ALTER INDEX` statement.
1614
1613
1615
-
```
1614
+
```sql
1616
1615
USE AdventureWorks2012;
1617
1616
GO
1618
1617
ALTER INDEX AK_Employee_LoginID
@@ -1642,7 +1641,7 @@ ALTER DATABASE AdventureWorks2012
1642
1641
1643
1642
To determine the current LOCK_TIMEOUT setting, execute the @@LOCK_TIMEOUT function:
1644
1643
1645
-
```
1644
+
```sql
1646
1645
SELECT @@lock_timeout;
1647
1646
GO
1648
1647
```
@@ -1665,7 +1664,7 @@ GO
1665
1664
1666
1665
The following example sets the `SERIALIZABLE` isolation level:
1667
1666
1668
-
```
1667
+
```sql
1669
1668
USE AdventureWorks2012;
1670
1669
GO
1671
1670
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
@@ -1682,7 +1681,7 @@ GO
1682
1681
1683
1682
To determine the transaction isolation level currently set, use the `DBCC USEROPTIONS` statement as shown in the following example. The result set may vary from the result seton your system.
1684
1683
1685
-
```
1684
+
```sql
1686
1685
USE AdventureWorks2012;
1687
1686
GO
1688
1687
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
@@ -1730,7 +1729,7 @@ GO
1730
1729
1731
1730
As shown in the following example, if the transaction isolation level is set to `SERIALIZABLE`, and the table-level locking hint `NOLOCK` is used with the `SELECT` statement, key-range locks typically used to maintain serializable transactions are not taken.
1732
1731
1733
-
```
1732
+
```sql
1734
1733
USE AdventureWorks2012;
1735
1734
GO
1736
1735
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
@@ -1787,7 +1786,7 @@ GO
1787
1786
1788
1787
The following example shows the intended use of nested transactions. The procedure `TransProc` enforces its transaction regardless of the transaction mode of any process that executes it. If `TransProc` is called when a transaction is active, the nested transaction in`TransProc` is largely ignored, and its INSERT statements are committed or rolled back based on the final action taken for the outer transaction. If `TransProc` is executed by a process that does not have an outstanding transaction, the COMMIT TRANSACTION at the end of the procedure effectively commits the INSERT statements.
Copy file name to clipboardExpand all lines: docs/2014/analysis-services/multidimensional-models/authorizing-access-to-objects-and-operations-analysis-services.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ ms.author: owend
34
34
35
35
2. Type the following query and press F5 to execute:
Copy file name to clipboardExpand all lines: docs/2014/analysis-services/relational-query-designer-ssas.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,7 +213,7 @@ ms.author: owend
213
213
#### Example
214
214
The following query returns the list of names from a table named `ContactType`.
215
215
216
-
```
216
+
```sql
217
217
SELECT Name FROM ContactType
218
218
```
219
219
@@ -236,7 +236,7 @@ SELECT Name FROM ContactType
236
236
#### Example
237
237
The following query calls the a stored procedure named `uspGetWhereUsedProductID`. When the stored procedure has input parameters you must provide parameter values when you run the query.
Copy file name to clipboardExpand all lines: docs/2014/data-quality-services/backing-up-and-restoring-dqs-databases.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,12 +55,11 @@ ms.author: lle
55
55
56
56
11. In the Query Editor window, copy the following SQL statements, and replace *\<PASSWORD>* with the password that you provided during the DQS installation for the database master key:
Copy file name to clipboardExpand all lines: docs/2014/data-quality-services/configure-advanced-settings-for-dqs-log-files.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,8 +32,8 @@ ms.author: lle
32
32
## <aname="DQSServer"></a> Configure Data Quality Server Log Settings
33
33
The [!INCLUDE[ssDQSServer](../includes/ssdqsserver-md.md)] log settings are present in an XML format in the **VALUE** column of the **ServerLogging** row in the A_CONFIGURATION table in the DQS_MAIN database. You can run the following SQL query to view the configuration information:
34
34
35
-
```
36
-
select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging'
35
+
```sql
36
+
select*fromDQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging';
37
37
```
38
38
39
39
You must update the appropriate information in the **VALUE** column of the **ServerLogging** row to change the configuration settings for [!INCLUDE[ssDQSServer](../includes/ssdqsserver-md.md)] logging. In this example, we will update the [!INCLUDE[ssDQSServer](../includes/ssdqsserver-md.md)] log settings to set the rolling file size limit to 25000 KB (the default is 20000 KB).
@@ -44,7 +44,7 @@ select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging'
44
44
45
45
3. In the Query Editor window, copy the following SQL statements:
46
46
47
-
```
47
+
```sql
48
48
-- Begin the transaction.
49
49
BEGIN TRAN
50
50
GO
@@ -90,14 +90,13 @@ select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging'
90
90
91
91
5. To apply changes done to the [!INCLUDE[ssDQSServer](../includes/ssdqsserver-md.md)] logging configuration, you must run the following Transact-SQL statements. Open a new Query Editor window, and paste the following Transact-SQL statements:
0 commit comments