Skip to content

Commit b698a11

Browse files
authored
added sql colorizer
and capitalized the keywords
1 parent fd51e04 commit b698a11

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

docs/t-sql/functions/next-value-for-transact-sql.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ ms.author: jrasnick
3535

3636
## Syntax
3737

38-
```
39-
38+
```syntaxsql
4039
NEXT VALUE FOR [ database_name . ] [ schema_name . ] sequence_name
4140
[ OVER (<over_order_by_clause>) ]
4241
```
@@ -168,7 +167,7 @@ NEXT VALUE FOR [ database_name . ] [ schema_name . ] sequence_name
168167

169168
The following examples use a sequence named `CountBy1` in a schema named `Test`. Execute the following statement to create the `Test.CountBy1` sequence. Examples C and E use the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database, so the `CountBy1` sequence is created in that database.
170169

171-
```
170+
```sql
172171
USE AdventureWorks2012 ;
173172
GO
174173

@@ -184,7 +183,7 @@ GO
184183
### A. Using a sequence in a select statement
185184
The following example creates a sequence named `CountBy1` that increases by one every time that it is used.
186185

187-
```
186+
```sql
188187
SELECT NEXT VALUE FOR Test.CountBy1 AS FirstUse;
189188
SELECT NEXT VALUE FOR Test.CountBy1 AS SecondUse;
190189
```
@@ -202,10 +201,10 @@ SecondUse
202201
### B. Setting a variable to the next sequence value
203202
The following example demonstrates three ways to set a variable to the next value of a sequence number.
204203

205-
```
206-
DECLARE @myvar1 bigint = NEXT VALUE FOR Test.CountBy1
207-
DECLARE @myvar2 bigint ;
208-
DECLARE @myvar3 bigint ;
204+
```sql
205+
DECLARE @myvar1 BIGINT = NEXT VALUE FOR Test.CountBy1
206+
DECLARE @myvar2 BIGINT ;
207+
DECLARE @myvar3 BIGINT ;
209208
SET @myvar2 = NEXT VALUE FOR Test.CountBy1 ;
210209
SELECT @myvar3 = NEXT VALUE FOR Test.CountBy1 ;
211210
SELECT @myvar1 AS myvar1, @myvar2 AS myvar2, @myvar3 AS myvar3 ;
@@ -214,7 +213,7 @@ GO
214213

215214
### C. Using a sequence with a ranking window function
216215

217-
```
216+
```sql
218217
USE AdventureWorks2012 ;
219218
GO
220219

@@ -227,16 +226,16 @@ GO
227226
### D. Using the NEXT VALUE FOR function in the definition of a default constraint
228227
Using the **NEXT VALUE FOR** function in the definition of a default constraint is supported. For an example of using **NEXT VALUE FOR** in a **CREATE TABLE** statement, see Example C[Sequence Numbers](../../relational-databases/sequence-numbers/sequence-numbers.md). The following example uses `ALTER TABLE` to add a sequence as a default to a current table.
229228

230-
```
229+
```sql
231230
CREATE TABLE Test.MyTable
232231
(
233-
IDColumn nvarchar(25) PRIMARY KEY,
234-
name varchar(25) NOT NULL
232+
IDColumn NVARCHAR(25) PRIMARY KEY,
233+
name VARCHAR(25) NOT NULL
235234
) ;
236235
GO
237236

238237
CREATE SEQUENCE Test.CounterSeq
239-
AS int
238+
AS INT
240239
START WITH 1
241240
INCREMENT BY 1 ;
242241
GO
@@ -259,10 +258,10 @@ GO
259258
### E. Using the NEXT VALUE FOR function in an INSERT statement
260259
The following example creates a table named `TestTable` and then uses the `NEXT VALUE FOR` function to insert a row.
261260

262-
```
261+
```sql
263262
CREATE TABLE Test.TestTable
264-
(CounterColumn int PRIMARY KEY,
265-
Name nvarchar(25) NOT NULL) ;
263+
(CounterColumn INT PRIMARY KEY,
264+
Name NVARCHAR(25) NOT NULL) ;
266265
GO
267266

268267
INSERT Test.TestTable (CounterColumn,Name)
@@ -271,13 +270,12 @@ GO
271270

272271
SELECT * FROM Test.TestTable;
273272
GO
274-
275273
```
276274

277275
### E. Using the NEXT VALUE FOR function with SELECT ... INTO
278276
The following example uses the `SELECT ... INTO` statement to create a table named `Production.NewLocation` and uses the `NEXT VALUE FOR` function to number each row.
279277

280-
```
278+
```sql
281279
USE AdventureWorks2012 ;
282280
GO
283281

@@ -293,7 +291,7 @@ GO
293291
### F. Granting permission to execute NEXT VALUE FOR
294292
The following example grants **UPDATE** permission to a user named `AdventureWorks\Larry` permission to execute `NEXT VALUE FOR` using the `Test.CounterSeq` sequence.
295293

296-
```
294+
```sql
297295
GRANT UPDATE ON OBJECT::Test.CounterSeq TO [AdventureWorks\Larry] ;
298296
```
299297

0 commit comments

Comments
 (0)