DB2 relational database query statement basic syntax

Source: Internet
Author: User
Tags definition db2

DB2 provides query language SQL (Structured Query Language) of the related database, which is a very colloquial, easy to learn and understandable syntax. This language is almost always required by every database system to represent connected operations, including the definition of data (DDL) and Data Processing (DML). SQL originally spelled sequel, the language of the prototype of "System R" in the name of the IBM San Jose Laboratory completed, through the internal IBM and many other usability and efficiency testing, the results are quite satisfactory, and decided to develop the system R technology based on IBM's products. And the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO) in 1987 follow an almost IBM-SQL based standard related data language definition.

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.

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.