The Access database adds fields with SQL statements, modifies fields, deletes fields _access

Source: Internet
Author: User
Tags access database
Here's an example:
Creates a table Table1 with the DDL create TABLE, the primary key is an AutoNumber field, and the other is a text field with a length of 10.
Copy Code code as follows:

CREATE TABLE Table1 (Id COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, MyText TEXT (10))


To build a table Table2 with two fields, the field ID is a long integer, and the field MyText is text
Copy Code code as follows:

CREATE TABLE Table2 (Id LONG, MyText TEXT)


Use the following statement to establish a one-to-many relationship between Table1 and Table2, cascade Update, Cascade Delete:
Copy Code code as follows:

ALTER TABLE Table2 ADD CONSTRAINT Relation1 FOREIGN KEY ([id]) REFERENCES Table1 ([id]) on UPDATE CASCADE on DELETE Cascad E


Delete a relationship with the following statement:
Copy Code code as follows:

ALTER TABLE Table2 DROP CONSTRAINT Relation1


Delete Table1 with the following statement:
Copy Code code as follows:

DROP TABLE Table1


Set a field as the primary key
Copy Code code as follows:

ALTER TABLE 1 ALTER COLUMN [ID] COUNTER CONSTRAINT myprimarykey PRIMARY KEY


Add a field mysalary
Copy Code code as follows:

ALTER TABLE AAA add COLUMN mysalary CURRENCY


Delete a field mysalary
Copy Code code as follows:

ALTER TABLE AAA drop COLUMN mysalary

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.