On the use of identity

Source: Internet
Author: User

"Learn a little bit" when learning SQL, many people will deal with identity. Of course, I have only just learned it. Here I write out the identity I understand. Recording

A moment. Because my mind is not very good. Want to deepen understanding and memory in this way. The understanding of identity is all thanks to the Csdn brothers. Thank you here.

Before we understand it, we'll build two tables create TABLE [TA] ([a] char,[b] char); CREATE TABLE [TB] ([C] char)

To implement a merge of a table. But neither table has a primary key. It is easy for us to use it. Identity (int, 1, 1) can automatically implement numbering.

SELECT *, id= identity (int, 1,1) into the ta1 from TA//

SELECT *, id= identity (int, 1,1) into the tb1 from tb//

This allows us to copy the column values of the TA,TB into the table ta1,tb1 and add the ID column.

This makes it easy to combine two tables.

The identity (INT,I,J) Implementation ID increases from I, each time with J. 】

"SELECT * into table1 from table2//execute this SQL statement: Copy all table2 values into table1. 】

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.