Skip to content

Commit b00e365

Browse files
authored
Merge pull request MicrosoftDocs#8277 from pmasl/patch-398
Update deallocate-transact-sql.md
2 parents f0bed0d + c7cc5c7 commit b00e365

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

docs/t-sql/language-elements/deallocate-transact-sql.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,48 @@ manager: craigg
3333
## Syntax
3434

3535
```
36-
3736
DEALLOCATE { { [ GLOBAL ] cursor_name } | @cursor_variable_name }
3837
```
3938

4039
## Arguments
4140
*cursor_name*
42-
Is the name of an already declared cursor. If both a global and a local cursor exist with *cursor_name* as their name, *cursor_name* refers to the global cursor if GLOBAL is specified and to the local cursor if GLOBAL is not specified.
41+
Is the name of an already declared cursor. If both a global and a local cursor exist with *cursor_name* as their name, *cursor_name* refers to the global cursor if `GLOBAL` is specified and to the local cursor if `GLOBAL` is not specified.
4342

4443
@*cursor_variable_name*
4544
Is the name of a **cursor** variable. @*cursor_variable_name* must be of type **cursor**.
4645

4746
## Remarks
48-
Statements that operate on cursors use either a cursor name or a cursor variable to refer to the cursor. DEALLOCATE removes the association between a cursor and the cursor name or cursor variable. If a name or variable is the last one referencing the cursor, the cursor is deallocated and any resources used by the cursor are freed. Scroll locks used to protect the isolation of fetches are freed at DEALLOCATE. Transaction locks used to protect updates, including positioned updates made through the cursor, are held until the end of the transaction.
47+
Statements that operate on cursors use either a cursor name or a cursor variable to refer to the cursor. `DEALLOCATE` removes the association between a cursor and the cursor name or cursor variable. If a name or variable is the last one referencing the cursor, the cursor is deallocated and any resources used by the cursor are freed. Scroll locks used to protect the isolation of fetches are freed at `DEALLOCATE`. Transaction locks used to protect updates, including positioned updates made through the cursor, are held until the end of the transaction.
4948

50-
The DECLARE CURSOR statement allocates and associates a cursor with a cursor name.
49+
The `DECLARE CURSOR` statement allocates and associates a cursor with a cursor name.
5150

52-
```
51+
```sql
5352
DECLARE abc SCROLL CURSOR FOR
5453
SELECT * FROM Person.Person;
5554
```
5655

57-
After a cursor name is associated with a cursor, the name cannot be used for another cursor of the same scope (GLOBAL or LOCAL) until this cursor has been deallocated.
56+
After a cursor name is associated with a cursor, the name cannot be used for another cursor of the same scope (global or local) until this cursor has been deallocated.
5857

5958
A cursor variable is associated with a cursor using one of two methods:
6059

61-
- By name using a SET statement that sets a cursor to a cursor variable.
60+
- By name using a `SET` statement that sets a cursor to a cursor variable.
6261

63-
```
62+
```sql
6463
DECLARE @MyCrsrRef CURSOR;
6564
SET @MyCrsrRef = abc;
6665
```
6766

6867
- A cursor can also be created and associated with a variable without having a cursor name defined.
6968

70-
```
69+
```sql
7170
DECLARE @MyCursor CURSOR;
7271
SET @MyCursor = CURSOR LOCAL SCROLL FOR
7372
SELECT * FROM Person.Person;
7473
```
7574

76-
A DEALLOCATE @*cursor_variable_name* statement removes only the reference of the named variable to the cursor. The variable is not deallocated until it goes out of scope at the end of the batch, stored procedure, or trigger. After a DEALLOCATE @*cursor_variable_name* statement, the variable can be associated with another cursor using the SET statement.
75+
A `DEALLOCATE <@cursor_variable_name>` statement removes only the reference of the named variable to the cursor. The variable is not deallocated until it goes out of scope at the end of the batch, stored procedure, or trigger. After a `DEALLOCATE <@cursor_variable_name>` statement, the variable can be associated with another cursor using the SET statement.
7776

78-
```
77+
```sql
7978
USE AdventureWorks2012;
8079
GO
8180
@@ -90,15 +89,15 @@ SET @MyCursor = CURSOR LOCAL SCROLL FOR
9089
GO
9190
```
9291

93-
A cursor variable does not have to be explicitly deallocated. The variable is implicitly deallocated when it goes out of scope.
92+
A cursor variable does not have to be explicitly deallocated. The variable is implicitly deallocated when it goes out of scope.
9493

9594
## Permissions
96-
DEALLOCATE permissions default to any valid user.
95+
Permissions for `DEALLOCATE` default to any valid user.
9796

9897
## Examples
9998
The following script shows how cursors persist until the last name or until the variable referencing them has been deallocated.
10099

101-
```
100+
```sql
102101
USE AdventureWorks2012;
103102
GO
104103
-- Create and open a global named cursor that

0 commit comments

Comments
 (0)