Auto-increment variable settings for Oracle, SQLServer, and MySQL _ MySQL

Source: Internet
Author: User
Auto-increment variable settings for Oracle, SQL Server, and MySQL:

1. MySQL's auto-incrementing variables are easy to remember. use the AUTO_INCREMENT keyword. if you know English, it is easy to remember. create a table with auto-incrementing mechanism as follows.

Createtabletest (idintAUTO_INCREMENT
Primarykeynotnull, namevarchar (50 ));

Note: The id must be declared as the primary key. Otherwise, an error is returned.

2. when SQL Server uses the identity keyword, it is easy to specify the starting number and increasing value as follows:

Createtabletest (idintidentity (100,10)
Primarykeynotnull, namevarchar (50 ));

3. Oracle cannot specify an automatic keyword when creating a table. it needs to re-create the sequence and reference it with "create key. nextval:

Createtabletest (idintprimarykey
Notnull, namevarchar (50 ));
Createsequencetest_id (preferably table name + serial number mark)
Incrementby1startwith1maxvalue9999;

Reference:

Insertintotest (test_id.nextval, 'WWW ');

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.