Use after an SQL statement
SCOPE_IDENTITY ()
Of course, you can also use SELECT @ IDENTITY
However, the use of SELECT @ IDENTITY is globally up-to-date. incorrect values may be obtained.
Example:Copy codeThe Code is as follows: insert into dbo. SNS_BlogData (userName) values ('jiangyun ');SELECT SCOPE_IDENTITY ()
Gets the primary key return value for the insert
* From sysindexkeys-- Each index and table in the database occupies one row in the table.-- Sysindexkeys. ID table ID-- Sysindexkeys. indid index ID type-- Sysindexkeys. colid column ID
The primary key must be a unique index. The unique index is not necessarily a primary key.
A
Original: Deletes all indexes of the specified table, including primary key indexes, unique indexes, and normal indexes, for SQL Server 2005.Deletes all indexes of the specified table, including primary key indexes, unique indexes, and normal indexes, for
Many people may confuse PrimaryKey with clustered index, or think this is the same thing. This concept is very incorrect. A primary key is a constraint attached to an index. This index can be a clustered index or a non-clustered index. So on one (or a group) Field
Many people may confuse Primary Key with clustered ind
SQL Multiple primary key tables, when the inserted data is duplicated, are prompted to violate the primary KEY constraint that cannot be inserted by the error. So, how do I find duplicate values for the inserted data? Workaround: Use Group bySuppose there is a table #a , t
Subject:
How to write an SQL statement that modifies the field type to "ID" and sets this field as the primary key ??
Author:
China_skag ()
Level 1:
Reputation value:
100
Forum:
MS-
Label:The last day of 2014, today when importing data to the database, there is a problem, is the joint primary key to go heavy.The thing is, there is a table m, I want to find a table that imports a lot of data, and I need to set the fields a (int) and B (int) union as the primary key.But when I set the primary
Label:Add the settings for the database multi-field composite primary key.First, a table cannot have more than one primary key. But there are multiple fields that can be combined into one primary key, which is why sometimes the table has multiple fields with a
SELECT primary key Column Id=b.rkey, primary key Column name = (SELECT name from syscolumns WHERE Colid=b.rkey and Id=b.rkeyid), FOREIGN key table Id=b.fkeyid, foreign key table name =object_name (B.fkeyid), Foreign
that does not have duplicate values and does not update operations at all. Also, in a SQL Server database, a clustered index can have only one table. Therefore, the clustering index is very important and needs to be left to more important fields to use. Therefore, the index is created here in a nonclustered way, in contrast to the above table and the importance of the clustering index.
Specific applicatio
SQL: insert all other columns of rows with the same primary key updated.
In SQL writing, we often encounter such problems. During each insert operation, you must determine whether the data table already exists. For the same data, all the columns except the primary
-null
Delete A Field
Alter table mytable DROP field name;
Add unique key
Alter table 'test2' add unique ('userid ')
Modify primary key
Alter table 'test2' drop primary key, add primary key
Oracle Database primary key auto-increment SQL
We all know that in MySQL, it is very easy to implement automatic increment of primary keys. you only need to add auto_increment after the primary key definition, but this is not the
transactions. The user name is written to the users table, and the department it owns is written to the Userdepart table, and the transaction mechanism is used to ensure that the two steps either succeed at the same time or fail at the same time. The problem is that when the first step is complete, we don't know what the value of the Id_user to write to the second step, because this value is automatically generated by SQL Server. Solution Ideas: You
withno_logDBCCshrinkdatabase (database name)execsp_dboption \'database name \', \'autoshrink\', \'true\'
\\\'Add field General function Sub AddColumn (tablename,columnname,columntype) Conn.execute (\ "Alter Table \" tablename\ "add \" columnname\ "\" columntype\ "\") End Sub \\\'Change the field general function Sub Modcolumn (tablename,columnname,columntype) Conn.Execute(\"Alter Table\"TableName\"Alter Column\"ColumnName\" \"ColumnType\"\")
EndSub \\\'Check if the table exists
Add a table field
ALTER TABLE table1 add transactor varchar (a) not Null;
ALTER TABLE table1 add ID int unsigned not Null auto_increment primary key
Modify the field type of a table and specify null or Non-empty
ALTER TABLE name change field Name field name FieldSize field type [Allow Non-null];
ALTER TABLE name modify field Name field type [Allow Non-null];
ALTER TABLE name modify field Name field ty
-- SQL creates a primary key for all user data tables in the database-- Primary key Description: The name is ID, and the data type is Integer auto-increment.
-- Query all constraints of the current database before creationSelect * From information_schema.key_column_usage
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.