Automatic SQL server number

Source: Internet
Author: User
SQL Server automatic numbering and comparison.

I. UseProgramObtain the database ID. Insert the obtained ID number when inserting the record. Advantage: flexible. Disadvantage: You need to interact with the database twice. When inserting data, you must execute "insert into tablename values (" & getmaxid & ", 'value')", where getmaxid is the function for obtaining the ID.

2. Use a database trigger to insert an ID number. Advantage: flexible. Fast. The disadvantage is that it is relatively complicated. You need to perform some program processing on the database. When inserting data, you only need to insert into tablename values (0, 'value.

Iii. Using the labels provided by SQL Server, you can easily implement automatic database numbers. The disadvantage is that it is not flexible and cannot meet the user's needs. The insert into tablename (name) value ('value') must be used because the value cannot be inserted in the label column during record insertion ');. Advantages: simple operation and high speed

4. Add a seed field (ID) SQL Server automatic number field /////////////////////////////////// /////

Alter table Table1 add ID int identity (1, 1)

Related Article

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.