Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit abfe1dc

Browse files
authored
Merge pull request #5089 from MikeyBronowski/FormattingSQL
Formatting sql
2 parents 5dd4964 + 9c8e8a8 commit abfe1dc

17 files changed

Lines changed: 129 additions & 111 deletions

docs/2014/2014-toc/sql-server-transaction-locking-and-row-versioning-guide.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ GO
225225

226226
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.
227227

228-
```
228+
```sql
229229
--Transaction 1
230230
BEGIN TRAN;
231231
SELECT ID FROM dbo.employee
@@ -234,10 +234,9 @@ GO
234234
SELECT ID FROM dbo.employee
235235
WHERE ID > 5 and ID < 10;
236236
COMMIT;
237-
238237
```
239238

240-
```
239+
```sql
241240
--Transaction 2
242241
BEGIN TRAN;
243242
INSERT INTO dbo.employee
@@ -566,7 +565,7 @@ GO
566565

567566
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:
568567

569-
```
568+
```sql
570569
SELECT name
571570
FROM mytable
572571
WHERE name BETWEEN 'A' AND 'C';
@@ -581,7 +580,7 @@ SELECT name
581580

582581
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:
583582

584-
```
583+
```sql
585584
SELECT name
586585
FROM mytable
587586
WHERE name = 'Bill';
@@ -593,7 +592,7 @@ SELECT name
593592

594593
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:
595594

596-
```
595+
```sql
597596
DELETE mytable
598597
WHERE name = 'Bob';
599598
```
@@ -606,7 +605,7 @@ DELETE mytable
606605

607606
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:
608607

609-
```
608+
```sql
610609
INSERT mytable VALUES ('Dan');
611610
```
612611

@@ -970,7 +969,7 @@ deadlock-list
970969
971970
These [!INCLUDE[tsql](../includes/tsql-md.md)] statements create test objects that are used in the examples that follow.
972971
973-
```
972+
```sql
974973
-- Create a test table.
975974
CREATE TABLE TestTable
976975
(col1 int);
@@ -992,7 +991,7 @@ GO
992991

993992
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.
994993

995-
```
994+
```sql
996995
-- Start a transaction.
997996
BEGIN TRANSACTION
998997
-- This SELECT statement will acquire an IS lock on the table.
@@ -1005,7 +1004,7 @@ BEGIN TRANSACTION
10051004

10061005
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.
10071006

1008-
```
1007+
```sql
10091008
BEGIN TRANSACTION
10101009
SELECT col1
10111010
FROM TestTable
@@ -1016,7 +1015,7 @@ BEGIN TRANSACTION
10161015

10171016
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.
10181017

1019-
```
1018+
```sql
10201019
SELECT col1
10211020
FROM TestTable
10221021
WITH (TABLOCKX);
@@ -1028,7 +1027,7 @@ SELECT col1
10281027

10291028
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.
10301029

1031-
```
1030+
```sql
10321031
-- Start a transaction.
10331032
BEGIN TRANSACTION
10341033
-- This SELECT statement will acquire an IS lock on the table.
@@ -1043,7 +1042,7 @@ BEGIN TRANSACTION
10431042

10441043
On partition IDs 7-15 that the X lock has not yet reached, other transactions can continue to acquire locks.
10451044

1046-
```
1045+
```sql
10471046
BEGIN TRANSACTION
10481047
SELECT col1
10491048
FROM TestTable
@@ -1308,7 +1307,7 @@ BEGIN TRANSACTION
13081307

13091308
On session 1:
13101309

1311-
```
1310+
```sql
13121311
USE AdventureWorks2012; -- Or the 2008 or 2008R2 version of the AdventureWorks database.
13131312
GO
13141313

@@ -1331,7 +1330,7 @@ BEGIN TRANSACTION;
13311330

13321331
On session 2:
13331332

1334-
```
1333+
```sql
13351334
USE AdventureWorks2012;
13361335
GO
13371336

@@ -1353,7 +1352,7 @@ BEGIN TRANSACTION;
13531352

13541353
On session 1:
13551354

1356-
```
1355+
```sql
13571356
-- Reissue the SELECT statement - this shows
13581357
-- the employee having 48 vacation hours. The
13591358
-- snapshot transaction is still reading data from
@@ -1365,7 +1364,7 @@ BEGIN TRANSACTION;
13651364

13661365
On session 2:
13671366

1368-
```
1367+
```sql
13691368
-- Commit the transaction; this commits the data
13701369
-- modification.
13711370
COMMIT TRANSACTION;
@@ -1374,7 +1373,7 @@ GO
13741373

13751374
On session 1:
13761375

1377-
```
1376+
```sql
13781377
-- Reissue the SELECT statement - this still
13791378
-- shows the employee having 48 vacation hours
13801379
-- even after the other transaction has committed
@@ -1409,7 +1408,7 @@ GO
14091408

14101409
On session 1:
14111410

1412-
```
1411+
```sql
14131412
USE AdventureWorks2012; -- Or any earlier version of the AdventureWorks database.
14141413
GO
14151414

@@ -1436,7 +1435,7 @@ BEGIN TRANSACTION;
14361435

14371436
On session 2:
14381437

1439-
```
1438+
```sql
14401439
USE AdventureWorks2012;
14411440
GO
14421441

@@ -1459,7 +1458,7 @@ BEGIN TRANSACTION;
14591458

14601459
On session 1:
14611460

1462-
```
1461+
```sql
14631462
-- Reissue the SELECT statement - this still shows
14641463
-- the employee having 48 vacation hours. The
14651464
-- read-committed transaction is still reading data
@@ -1473,7 +1472,7 @@ BEGIN TRANSACTION;
14731472

14741473
On session 2:
14751474

1476-
```
1475+
```sql
14771476
-- Commit the transaction.
14781477
COMMIT TRANSACTION;
14791478
GO
@@ -1482,7 +1481,7 @@ GO
14821481

14831482
On session 1:
14841483

1485-
```
1484+
```sql
14861485
-- Reissue the SELECT statement which now shows the
14871486
-- employee having 40 vacation hours. Being
14881487
-- read-committed, this transaction is reading the
@@ -1512,7 +1511,7 @@ GO
15121511

15131512
The following [!INCLUDE[tsql](../includes/tsql-md.md)] statement enables READ_COMMITTED_SNAPSHOT:
15141513

1515-
```
1514+
```sql
15161515
ALTER DATABASE AdventureWorks2012
15171516
SET READ_COMMITTED_SNAPSHOT ON;
15181517
```
@@ -1521,7 +1520,7 @@ ALTER DATABASE AdventureWorks2012
15211520

15221521
The following [!INCLUDE[tsql](../includes/tsql-md.md)] statement will enable ALLOW_SNAPSHOT_ISOLATION:
15231522

1524-
```
1523+
```sql
15251524
ALTER DATABASE AdventureWorks2012
15261525
SET ALLOW_SNAPSHOT_ISOLATION ON;
15271526
```
@@ -1551,7 +1550,7 @@ ALTER DATABASE AdventureWorks2012
15511550

15521551
- Read-committed that uses row versioning by setting the `READ_COMMITTED_SNAPSHOT` database option to `ON` as shown in the following code example:
15531552

1554-
```
1553+
```sql
15551554
ALTER DATABASE AdventureWorks2012
15561555
SET READ_COMMITTED_SNAPSHOT ON;
15571556
```
@@ -1560,14 +1559,14 @@ ALTER DATABASE AdventureWorks2012
15601559

15611560
- Snapshot isolation by setting the `ALLOW_SNAPSHOT_ISOLATION` database option to `ON` as shown in the following code example:
15621561

1563-
```
1562+
```sql
15641563
ALTER DATABASE AdventureWorks2012
15651564
SET ALLOW_SNAPSHOT_ISOLATION ON;
15661565
```
15671566

15681567
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.
15691568

1570-
```
1569+
```sql
15711570
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
15721571
BEGIN TRAN
15731572
SELECT t1.col5, t2.col5
@@ -1578,7 +1577,7 @@ ALTER DATABASE AdventureWorks2012
15781577

15791578
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.
15801579

1581-
```
1580+
```sql
15821581
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
15831582
BEGIN TRAN
15841583
SELECT t1.col5, t2.col5
@@ -1612,7 +1611,7 @@ ALTER DATABASE AdventureWorks2012
16121611

16131612
For example, a database administrator executes the following `ALTER INDEX` statement.
16141613

1615-
```
1614+
```sql
16161615
USE AdventureWorks2012;
16171616
GO
16181617
ALTER INDEX AK_Employee_LoginID
@@ -1642,7 +1641,7 @@ ALTER DATABASE AdventureWorks2012
16421641

16431642
To determine the current LOCK_TIMEOUT setting, execute the @@LOCK_TIMEOUT function:
16441643

1645-
```
1644+
```sql
16461645
SELECT @@lock_timeout;
16471646
GO
16481647
```
@@ -1665,7 +1664,7 @@ GO
16651664

16661665
The following example sets the `SERIALIZABLE` isolation level:
16671666

1668-
```
1667+
```sql
16691668
USE AdventureWorks2012;
16701669
GO
16711670
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
@@ -1682,7 +1681,7 @@ GO
16821681

16831682
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 set on your system.
16841683

1685-
```
1684+
```sql
16861685
USE AdventureWorks2012;
16871686
GO
16881687
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
@@ -1730,7 +1729,7 @@ GO
17301729

17311730
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.
17321731

1733-
```
1732+
```sql
17341733
USE AdventureWorks2012;
17351734
GO
17361735
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
@@ -1787,7 +1786,7 @@ GO
17871786

17881787
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.
17891788

1790-
```
1789+
```sql
17911790
SET QUOTED_IDENTIFIER OFF;
17921791
GO
17931792
SET NOCOUNT OFF;

docs/2014/analysis-services/multidimensional-models/authorizing-access-to-objects-and-operations-analysis-services.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ms.author: owend
3434

3535
2. Type the following query and press F5 to execute:
3636

37-
```
37+
```sql
3838
Select * from $SYSTEM.DBSCHEMA_CATALOGS
3939
```
4040

docs/2014/analysis-services/relational-query-designer-ssas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ ms.author: owend
213213
#### Example
214214
The following query returns the list of names from a table named `ContactType`.
215215

216-
```
216+
```sql
217217
SELECT Name FROM ContactType
218218
```
219219

@@ -236,7 +236,7 @@ SELECT Name FROM ContactType
236236
#### Example
237237
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.
238238

239-
```
239+
```sql
240240
uspGetWhereUsedProductID
241241
```
242242

docs/2014/data-quality-services/backing-up-and-restoring-dqs-databases.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ ms.author: lle
5555

5656
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:
5757

58-
```
58+
```sql
5959
USE [DQS_MAIN]
6060
GO
6161
EXECUTE [internal_core].[RestoreDQDatabases] '<PASSWORD>'
6262
GO
63-
6463
```
6564

6665
12. Press F5 to execute the statements. Check the **Results** pane to verify that the statements have executed successfully.

docs/2014/data-quality-services/configure-advanced-settings-for-dqs-log-files.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ ms.author: lle
3232
## <a name="DQSServer"></a> Configure Data Quality Server Log Settings
3333
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:
3434

35-
```
36-
select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging'
35+
```sql
36+
select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging';
3737
```
3838

3939
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'
4444

4545
3. In the Query Editor window, copy the following SQL statements:
4646

47-
```
47+
```sql
4848
-- Begin the transaction.
4949
BEGIN TRAN
5050
GO
@@ -90,14 +90,13 @@ select * from DQS_MAIN.dbo.A_CONFIGURATION where NAME='ServerLogging'
9090

9191
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:
9292

93-
```
93+
```sql
9494
USE [DQS_MAIN]
9595
GO
9696
DECLARE @return_value int
9797
EXEC @return_value = [internal_core].[RefreshLogSettings]
9898
SELECT 'Return Value' = @return_value
9999
GO
100-
101100
```
102101

103102
6. Press F5 to execute the statements. Check the **Results** pane to verify that the statements have executed successfully.

0 commit comments

Comments
 (0)