The access database uses SQL statements to add, modify, and delete fields.

Source: Internet
Author: User
Microsoft's Access includes DataDefinitionLanguage (DDL) to create and Delete tables and relationships. Of course, this can also be solved using DAO.

Microsoft's Access includes Data Definition Language (DDL) to create and Delete tables and relationships. Of course, this can also be solved using DAO.

The following is an example:
Create Table with DDL to Create a Table Table1. The primary key is an automatically numbered field, and the other is a text field with a length of 10.
The Code is as follows:
Create table Table1 (Id counter constraint PrimaryKey primary key, MyText TEXT (10 ))


Create a table named Table2 that contains two fields. The field id is a long integer and the field MyText is text.
The Code is as follows:
Create table Table2 (Id LONG, MyText TEXT)


Use the following statement to create a one-to-multiple relationship between Table1 and Table2, cascade update, and cascade deletion:
The Code is as follows:
Alter table Table2 add constraint Relation1 foreign key ([Id]) REFERENCES Table1 ([Id]) ON UPDATE CASCADE ON DELETE CASCADE


Use the following statement to delete a link:
The Code is as follows:
Alter table Table2 drop constraint Relation1


To delete table 1, use the following statement:
The Code is as follows:
Drop table Table1


Set a field as the primary key
The Code is as follows:
Alter table 1 alter column [id] counter constraint MyPrimaryKey PRIMARY KEY


Add a field MySalary
The Code is as follows:
Alter table AAA add COLUMN MySalary CURRENCY


Delete a field MySalary
The Code is 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.