SQL Database ID Memo

xiaoxiao2021-03-06  115

• When the database is set to Identity, there are three ways to get insert to the table: Ident_Current ('Table Name): Returns the last identity value generated by the specified table @@ identity: Returns current session, all scope ( In the scope, any table generated, the last Identity value scope_identity: Returns the last Identity value of any table generated in the current session and current scope: assumptions INSERT to two tables T1, T2 with Identity columns before and after After the @@ identity value is the last Identity column value of T2. Ident_current ('T1') and Ident_current ('T2') are the last Identity column values ​​of T1 and T2, respectively. If the INSERT TRIGGER is written for T1, its content is inserted into T2. When the INSERT command is executed to the data to T1, then execute SELECT Scope_identity (), get the last Identity column value of the T1, although inserted data to T1 will trigger trigger SCOPEs are not in Insert Trigger in Insert Trigger. ? Identity () is usually used in Select ... INTO, which is used to create an Identity listing in a new form. Grammar: Identity (Data Type [, Start Value, Value]). NEWID () returns the GUID value. When you need to specify the Identity value in the insert statement, the following method: set identity_insert? Name OnInsert INTO Table Name (ID, Column 1, Column 2) VALUES (0, Column Value 1, Column Value 2) Set Identity_Insert Name OFF

转载请注明原文地址:https://www.9cbs.com/read-125688.html

New Post(0)