Check @@IDENTITY value : Identity « Sequence Indentity « SQL Server / T-SQL Tutorial

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
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL Tutorial » Sequence Indentity » Identity 
15. 1. 18. Check @@IDENTITY value
3>
4CREATE TABLE OrderDetails (
5>      OrderID int NOT NULL ,
6>      ProductID int NOT NULL ,
7>      UnitPrice money NOT NULL DEFAULT (0),
8>      Quantity smallint NOT NULL DEFAULT (1),
9>      Discount real NOT NULL DEFAULT (0)
10)
11> GO
1INSERT OrderDetails VALUES(10248,11,14,12,0)
2INSERT OrderDetails VALUES(10248,42,9.8,10,0)
3INSERT OrderDetails VALUES(10248,72,34.8,5,0)
4INSERT OrderDetails VALUES(10249,14,18.6,9,0)
5INSERT OrderDetails VALUES(10249,51,42.4,40,0)
6INSERT OrderDetails VALUES(10250,41,7.7,10,0)
7INSERT OrderDetails VALUES(10250,51,42.4,35,0.15)
8INSERT OrderDetails VALUES(10250,65,16.8,15,0.15)
9INSERT OrderDetails VALUES(10251,22,16.8,6,0.05)
10INSERT OrderDetails VALUES(10251,57,15.6,15,0.05)
11> go

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1>
2>
3CREATE TABLE Orders (
4>      OrderID int IDENTITY (11NOT NULL ,
5>      CustomerID nchar (5NULL ,
6>      EmployeeID int NULL ,
7>      OrderDate datetime NULL ,
8>      RequiredDate datetime NULL ,
9>      ShippedDate datetime NULL ,
10>     ShipVia int NULL ,
11>     Freight money NULL DEFAULT (0),
12>     ShipName nvarchar (40NULL ,
13>     ShipAddress nvarchar (60NULL ,
14>     ShipCity nvarchar (15NULL ,
15>     ShipRegion nvarchar (15NULL ,
16>     ShipPostalCode nvarchar (10NULL ,
17>     ShipCountry nvarchar (15NULL
18)
19> GO
1>
2>
3>    DECLARE @Ident int
4>
5>    INSERT INTO Orders
6>    (CustomerID,OrderDate)
7>    VALUES
8>    ('ALFKI', DATEADD(day,-1,GETDATE()))
9>
10>    SELECT @Ident = @@IDENTITY
11>
12>    INSERT INTO   OrderDetails
13>    (OrderID, ProductID, UnitPrice, Quantity)
14>    VALUES
15>    (@Ident, 15025)
16>
17>    SELECT 'The OrderID of the INSERTed row is ' + CONVERT(varchar(8),@Ident)
18> GO

(rows affected)

(rows affected)

-------------------------------------------
The OrderID of the INSERTed row is 1

(rows affected)
1>
2> drop table orders;
3> drop table OrderDetails;
4> GO
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.