How do I build tables and relationships with Jet SQL's DDL statements?
Microsoft Access contains data Definition language (DDL) to create a delete table and relationships, which, of course, can be solved with DAO.
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.
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
CREATE TABLE table2 (ID long, mytext text)
Establish a one-to-many relationship between Table1 and table2 with the following statement:
ALTER TABLE table2 ADD constraint relation1 foreign key ([id]) references table1 ([id])
Delete a relationship with the following statement:
ALTER TABLE table2 DROP constraint Relation1
Delete table1 with the following statement:
drop TABLE table1
Set a field as the primary key
ALTER TABLE 1 ALTER COLUMN [ID] counter constraint myprimarykey primary key
Add a field mysalary
ALTER TABLE AAA add column mysalary currency
Delete a field mysalary
ALTER TABLE AAA drop column Mysalary
How to run the above Jet SQL code, refer to the animated "How to run a Jet SQL code" in Http://access911.net, "How Flash painting Demonstrates how"