Storing the Results in a Temporary Table Using the IDENTITY() Function : Identity « Sequence Indentity « SQL Server / T-SQL Tutorial

Home
SQL Server / T-SQL Tutorial
1.Query
2.Insert Delete Update
3.Table
4.Table Join
5.Data Types
6.Set Operations
7.Constraints
8.Subquery
9.Aggregate Functions
10.Date Functions
11.Math Functions
12.String Functions
13.Data Convert Functions
14.Analytical Functions
15.Sequence Indentity
16.View
17.Index
18.Cursor
19.Database
20.Transact SQL
21.Procedure Function
22.Trigger
23.Transaction
24.XML
25.System Functions
26.System Settings
27.System Tables Views
28.User Role
29.CLR
SQL Server / T-SQL Tutorial » Sequence Indentity » Identity 
15.1.22.Storing the Results in a Temporary Table Using the IDENTITY() Function
4>
5CREATE TABLE MyTable (
6>  key_col int NOT NULL IDENTITY (1,1),
7>  abc     char(1NOT NULL
8)
9INSERT INTO MyTable VALUES ('a')
10INSERT INTO MyTable VALUES ('b')
11INSERT INTO MyTable VALUES ('c')
12SELECT FROM MyTable ORDER BY key_col
13> GO

(rows affected)

(rows affected)

(rows affected)
key_col     abc
----------- ---
          a
          b
          c

(rows affected)
1SELECT
2>  IDENTITY (int 11AS rownum,
3>  abc
4> INTO
5>  #temp
6FROM
7>  MyTable
8> ORDER BY
9>  abc
10>
11> --Retrieving the Results of Using the IDENTITY() Function from the Temporary Table
12SELECT
13>  *
14FROM
15>  #temp
16> ORDER BY
17>  Abc
18>
19> drop table MyTable
20> GO

(rows affected)
rownum      abc
----------- ---
          a
          b
          c

(rows affected)
1>
15.1.Identity
15.1.1.Using the IDENTITY Property and the IDENTITY() Function
15.1.2.Syntax for Using the IDENTITY() Function
15.1.3.Create table with IDENTITY column
15.1.4.Generating IDENTITY values
15.1.5.Cannot insert explicit value for identity column in table 'T' when IDENTITY_INSERT is set to OFF.
15.1.6.IDENTITY/NOT NULL/PRIMARY KEY
15.1.7.IDENTITY(100, 20)
15.1.8.Identity column
15.1.9.SELECT Statement and IDENTITY Property
15.1.10.Identity: A numerical value automatically assigned to a row any time a new row is added.
15.1.11.Supported data types for the IDENTITY property are TinyInt, SmallInt Int, BigInt, Decimal, and Numeric.
15.1.12.A table could also be created so that the seed value was negative and the increment was positive:
15.1.13.The IDENTITY property must be temporarily turned off when inserting a specific value.
15.1.14.SQL Server will choose the highest number as its current seed for a positive increment value or the lowest for a negative increment value.
15.1.15.Saving the @@IDENTITY Value in a Variable
15.1.16.SQL Server provides the @@IDENTITY global variable to hold that value.
15.1.17.Altering the Table to Add an Identity Column
15.1.18.Check @@IDENTITY value
15.1.19.Query a view with four table join
15.1.20.Retrieving the Maximum Value of key_col from MyTable
15.1.21.Query that Returns Result Row Numbers, Starting with 1 and Incrementing by 3
15.1.22.Storing the Results in a Temporary Table Using the IDENTITY() Function
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.