SQL data table

Source: Internet
Author: User

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:

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.