SQL Basic Syntax

Source: Internet
Author: User

The 1.SQL statement can be divided into the following 4 categories:

1.1 DDL (data definition Languages) statements that define different data segments, databases, tables, columns, indexes, and so on.

The definition of the database object. The commonly used statement keywords include create, drop, alter and so on.

Create DATABASE Database-name//Create a databaseCREATE TABLE TabName (col1 type1 [notNULL] [primary key],col2 type2 [notNULL],..)//Create a new tableCreate a new table from an existing surface a:create table tab_new like Tab_old (Create a new table with the old table) b:create table tab_new asSelectcol1,col2 tab_old definition only create [unique] index idxname on tabname (col ...)//Create an indexDrop INDEX Idxname//Delete IndexCREATE VIEW viewname asSelectStatement//Create a ViewDrop View ViewName//Delete a viewDrop Database dbname//Deleting a databasedrop table TabName//Delete a new tableAlter table tabname Add column col type//Add a column//Note: Columns cannot be deleted after they are added. DB2 the column plus the data type can not be changed, the only change is to increase the length of the varchar type. Alter table TabName Add primary key (COL)//Add primary KeyAlter table TabName Drop primary key (COL)//Delete primary Key

1.2 DML (Data manipulation Language) statement: Data manipulation statements for adding, deleting, updating, and querying database records, and for checking data integrity.

Common statement keywords include insert, delete, udpate, select, and so on.

1.3 DCL (Data Control Language) statement: A statement that controls the level of permission and access to different data segments directly.

These statements define the database, table, field, user's access rights, and security level. The main statement keywords include GRANT, revoke, and so on.

1.4 DQL (data query Language) statement: A database lookup statement that is used to retrieve information from one or more tables.

 

SQL Basic 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.