DB2 provides the query language SQL (structured query language) for relational databases. It is a colloquial, easy-to-learn and easy-to-understand syntax. This language is required by almost every database system to represent relational operations, including data definition ddl) and Data Processing dml ). SQL was originally spelled as sequel. The prototype of this language was completed in the IBM San Jose laboratory in the name of "system r". After many usability and efficiency tests within ibm and its members, the results were quite satisfactory, and decided to develop IBM products on the technical basis of system r. In addition, the American National Institute of Standards ansi) and the International Organization for Standardization (iso) comply with a standard relational data language definition that is almost Based on IBM SQL.
I. Data definition DDLdata definition language)
A document language is a language defined for the format and form of a document. It is the first thing that every database needs to create, the table relationships, column primary keys in the table, and the reference relationships between tables are all planned at the beginning.
1. Create a table:
create table table_name( column1 datatype [not null] [not null primary key], column2 datatype [not null], ...)
|
Note:
Datatype -- is the data format. For details, see the table.
Nut null-do you want to allow empty data ).
Primary key -- is the primary key of the table.
2. Change the table
alter table table_name add column column_name datatype
|
Note: Add a column without deleting the syntax of a column.
alter table table_name add primary key (column_name)
|
Note: You can change the table definition to set a column as a primary key.
alter table table_name drop primary key (column_name)
|
Delete the definition of the primary key.
3. Create an index
create index index_name on table_name (column_name)
|
Note: index the column of a table to increase the query speed.
4. Delete
drop table_name drop index_name
|
Ii. DDL data format PES ypes
Smallint is an integer of 16 bits.
An integer of 32-bit interger.
Decimal (p, s) p exact value and the decimal integer of s size. Exact value p refers to the number of digits after the decimal point. If not specified, the system is set to p = 5; s = 0.
Float 32-bit real number.
The real number of the double 64-bit element.
Char (n) n length string, n cannot exceed 254.
A string with an unfixed varchar (n) length and a maximum length of n. n cannot exceed 4000.
Graphic (n) is the same as char (n), but it is measured in double-bytes. n cannot exceed 127. This form supports two character-length fonts, such as Chinese characters.
For a dual-character string with a variable vargraphic (n) length and a maximum length of n, n cannot exceed 2000.
Date contains the year, month, and date.
Time contains hours, minutes, and seconds.
Timestamp includes year, month, day, hour, minute, second, And 1‰ seconds.