---------------DB2数据库常用语句---------------
--所有SQL语句,分号可加可不加;多条语句执行时必须加上。--SQL语句的执行顺序from -> where -> group by -> select -> order by--创建table(table_name=professor)
create table professor( khdxdh integer, hydh varchar(12), hymc varchar(100)) in tbs_pas --表结构所在表空间 index in tbs_idx --索引所在表空间 ;create unique index xpkkhdx_hy on table_name( khdxdh asc);--查询select * from professor--在SQL语句中实现换行select '中国'||chr(10)||'你好!!' from pas_vt--插入数据insert into professor(khdxdh,hydh,hymc) values (1,'001','zhangsan');insert into professor(khdxdh,hydh,hymc) select khdxdh,hydh,hymc from khdx_hy where hydh in ('0001','0002');--updateUPDATE PROFESSOR SET KHDXDH=2 WHERE KHDXDH=261;--删除表中数据DELETE FROM 表名称 WHERE 列名称 = 值--删除整个表(包括表结构)DROP TABLE 表名称--表中添加类ALTER TABLE table_name ADD column_name datatype--表中删除列ALTER TABLE table_name DROP COLUMN column_name--改变表中列的数据类型ALTER TABLE table_name ALTER COLUMN column_name set data type datatype;--创建表时,声明自增长字段CREATE TABLE sd_text ( xh INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY( START WITH 1, INCREMENT BY 1, CACHE 20000) , name varchar(10), age INTEGER NOT NULL, sal DECIMAL(25,4)) IN TBS_JXDX INDEX IN TBS_IDX;CREATE UNIQUE INDEX XPKsd_text ON sd_text( xh ASC);