Reproduced: http://blog.sina.com.cn/s/blog_67aaf4440100v01p.html, slightly modified.
--Create a database
Create Database ETP;
--Connect to database
Connect to ETP;
--Disconnect
Disconnect ETP;
--See what tables are in the current database
List tables;
--Delete Table
drop table studentinfo;
--Adding a constraint when creating a table 1
CREATE TABLE Studentinfo (
Stuno int NOT NULL,
Stuname varchar (8) NOT NULL,
Stuage int,
Stutel Char (8),
Constraint Pk_stuno primary KEY (Stuno),
Constraint un_stuname Unique (stuname),
Constraint ch_stuage Check (stuage>=0 and Stuage <150)
);
--Create a table with the addition of Constraint mode 2 (second, simple and convenient)
CREATE TABLE Studentinfo (
Stuno int NOT null primary key,
Stuname varchar (8) NOT null unique,
stuage int Check (stuage >=0 andstuage <150),
Stutel Char (8)
);
--View table structure
Describe table studentinfo;
Search and change of fields and additions
--Add Table field
ALTER TABLE studentinfo add Stubirth date;
ALTER TABLE studentinfo add ABC int;
--delete Field
ALTER TABLE studentinfo drop column ABC;
--Modify the field type
ALTER TABLE studentinfo ALTER COLUMN Stutel set data typechar (11); (color marked, differs from SQL Server)
--Add a non-null constraint
ALTER TABLE studentinfo ALTER COLUMN Stutel set not null; (color is marked, differs from SQL Server)
DB2 to build tables, add fields, delete fields, modify fields, and more