1. IDENTITY вûֱӸ£ϵͳԶάġ
2.ͱΪֵͣint, smallint, tinyint, decimal or numeric with scale 0
3.вΪ null
4.ڸȱʡֵ
5.ֻΪ(磺12-3)ΪСҲΪ0
6.ֵ(ֵ seed)ûãȱʡֵΪ1
@@IDENTITY
@@IDENTITY һ IDENTITY ֵЩINSERT SELECT INTO bulk copyڸû IDENTITY е¼ϵͳΪ nullжм¼뵽 IDENTITY У@@IDENTITY ʾһֵijִһ IDENTITY еıIJ@@IDENTITY ɴֵıв IDENTITY Уô @@IDENTITY Ϊ nullʧܣ@@IDENTITY ֵȻӣ IDENTITY ֤ݵԡ
@@IDENTITY ǵǰӵȫֱֻԵǰЧҲ˵ϿӺ@@IDENTITY Ϊ null ADO ˵@@IDENTITY Connection رڼģ Connection ĴڷΧЧ MTS УӴӵʽĹر(Connection.Close)ߵ SetAbortSetComplete֮ǰڼ䣬@@IDENTITY 塣
ʹ Truncate table ʹ IDENTITY ¿ʼ㡣
õ @@IDENTITY ֵ
ַ(´ʹ VBScript)
һ
Dim Conn, strSQL, Rs
Set Conn = CreateObject("ADODB.Connection")
' Open a connection to the database
Conn.Open("DSN=myDSN;UID=myUID;PWD=myPWD;")
' Insert a new record into the table
strSQL = "INSERT INTO mtTable (columnName) VALUES ('something')"
' Execute the SQL statement
Conn.Execute(strSQL)
' Get the @@IDENTITY.
strSQL = "SELECT @@IDENTITY AS NewID"
Set Rs = Conn.Execute(lsSQL)
NewID = Rs.Fields("NewID").value
' Close the connection
Conn.Close()
Set Conn = Nothing
( ADO 2.0 )
Dim Conn, strSQL, Rs
Set Conn = CreateObject("ADODB.Connection")
' Open a connection to the database
Conn.Open("DSN=myDSN;UID=myUID;PWD=myPWD;")
' Insert a new record into the table
lsSQL = "INSERT INTO myTable (columnName) VALUES ('something');" &_
"SELECT @@IDENTITY AS NewID;"
' Execute the SQL statement
Set Rs = Conn.Execute(lsSQL)
' Get the second resultset into a RecordSet object
Set Rs = Rs.NextRecordSet()
' Get the inserted ID
NewID = Rs.Fields("NewID").value
' Close the connection
Conn.Close()
Set Conn = Nothing
Dim Conn, strSQL, Rs
Set Conn = CreateObject("ADODB.Connection")
' Open a connection to the database
Conn.Open("DSN=myDSN;UID=myUID;PWD=myPWD;")
' Insert a new record into the table
strSQL = "SET NOCOUNT ON;" &_
"INSERT INTO myTable (columnName) VALUES ('something');" &_
"SELECT @@IDENTITY AS NewID;"
' Execute the SQL statement
Set Rs = Conn.Execute(lsSQL)
' Get the inserted ID
NewID = Rs.Fields("NewID").value
' Close the connection
Conn.Close()
Set Conn = Nothing