Use SQL statements to set or delete a primary key-constraint usage

Source: Internet
Author: User

Recently, you need to remove the primary key from a table in the ACCESS database in the program and then perform some operations. Then add the primary key. You can use this SQL statement to complete

 

Remove primary key

Alter table Table Name drop constraint primarykey

The above primarykey is the name of the Integrity Constraint, And the ACCESS database uses the default name primarykey for the primary key constraint. Of course, if the primary key constraint is named by another user, the corresponding changes will also be made here.

 

Add primary key

Alter table table name Add constraint primarykey primary key (primary key field name)

The first primarykey is the same as the above. It is the name of the Primary Key Integrity Constraint. The following primary key (primary key field) is of course the primary key constraint phrase. In addition to the primary key, it can also be the foreign key or check phrase.

For details, refer to the usage of constraint. It is used to add integrity constraints and specify the name of the constraints (so that you can delete the constraints later ). Constrain can also be used in the create statement to set constraints such as primary key, foreign key, and check when creating a table.

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.