Data tables can be divided into permanent tables and temporary tables, and temporary tables are automatically deleted when the user exits or the system resumes.
Temporary tables are divided into local temporary tables and global temporary tables, and when tables are created, the system determines whether a temporary or permanent table is based on the table name, and the table name of the temporary table contains two #. The maximum length of the table name, including #, is 20 characters.
1. Set up data tables
Use the CREATE TABLE statement to create a table in the following format:
The database specifies the location where the tables are built, and the current is the default.
Owner Specify table owners, default to current user
TABLE_NAME is the name of the new table
Col_name defines the column name of a table in which the column name must be unique, but the column names can be the same in different tables in the same database
DataType the data type of the specified column
Identity specifies that the column is an identity column, and its value is automatically inserted by the system. Each table can have an identity column, which cannot be updated by the user, and does not allow null values. The identity column data type can only be the system data type int, smallint, tinyint, numeric, decimal, and decimal places are not allowed when the identity column data type is numeric and decimal. For the identity column, seed is the base value for identity, and increment is the column value increment for the identity column. By default, both the seed and increment values are 1.
Cases:
CREATE TABLE Person
(
person_id INT IDENTITY (1,10),
Name CHAR (8) Not NULL
)
2. Modify the table
Use the ALTER TABLE statement to modify the table structure, add columns to it, or open, close existing constraints, add, delete constraints, and so on.
The ALTER table statement is formatted as:
ALTER TABLE [database.[ Owner]]table_name
The Add Item parameter description adds a column or table constraint to the table, where the column definition is the same as the column definition method in the CREATE TABLE statement.
The drop item description deletes the existing constraint in the table.
Cases:
ALTER TABLE Person
ADD
Country char (2) NULL
3. Delete Table
The DROP table statement is formatted as: