SQL Syntax Reference

Source: Internet
Author: User
Tags create index
I. Data definition DDL (data definition Language)
Data-setting language refers to the language defined in the format and form of data, he is the first to be set up when each database is to be established, what is the form of data, the form of a field key, tables and tables of the relationship between the reference and so on, are in the beginning must be planned.
1, build the form:
CREATE TABLE table_name (
COLUMN1 datatype [NOT NULL] [NOT NULL primary key],
COLUMN2 datatype [NOT NULL],
... )
Description
DataType--is the format of the data, as detailed in the table.
Nut null--Can you allow the data to be empty (no data has been filled in yet).
Primary key--is the primary key for this table.
2. Change the form
ALTER TABLE TABLE_NAME
Add Column column_name datatype
Description: Adds a field (without deleting a field's syntax.)
ALTER TABLE TABLE_NAME
Add primary key (column_name)
Description: Change the definition of a table to set a field as the primary key.
ALTER TABLE TABLE_NAME
Drop primary KEY (column_name)
Description: Delete the definition of the primary key.
3, the establishment of the index
CREATE INDEX index_name on table_name (column_name)
Description: Index The field of a table to increase the speed of the query.
4, delete
Drop table_name
Drop Index_name
Second, the data form datatypes
smallint
A 16-bit integer.
Interger
A 32-bit integer.
Decimal (P,s)
P exact value and s size decimal integer, the exact value P refers to the total number of values (digits) size value, S is the decimal
There are several numbers after the point. If not specifically specified, the system is set to p=5; S=0.
Float
A 32-bit real number.
Double
A 64-bit real number.
CHAR (n)
N-length string, n cannot exceed 254.
VARCHAR (n)
A string whose length is not fixed and its maximum length is n, which cannot exceed 4000.
Graphic (n)
Same as char (n), but its unit is two characters Double-bytes and N cannot exceed 127. This form is for
A font that supports two character lengths, such as Chinese text.
Vargraphic (N)
A two-character string with a variable length and a maximum length of n, and N cannot exceed 2000.
Date
Contains the year, month, and date.
Time
Contains the hours, minutes, and seconds.
Timestamp
Includes year, month, day, time, minutes, seconds, 1 per thousand seconds.
Iii. Data manipulation DML (data manipulation language)
After the data is defined, the next thing is the operation of the data. The operation of the data is nothing more than the addition of data (insert), query data (query), change data (update), delete data (delete) four modes, the following describes their syntax:

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.