DB2表管理的语句
来源:互联网 发布:python运维脚本交换机 编辑:程序博客网 时间:2024/04/30 13:40
DB2表管理的相关语句是学习DB2数据库系统的基础知识,下面就为您详细介绍一些DB2表管理语句,希望对您学习DB2表管理方面能有所帮助。
创建表
CREATE TABLE BOOKS
( BOOKID INTEGER,
BOOKNAME VARCHAR(100),
ISBN CHAR(10) )
使用like创建表
CREATE TABLE MYBOOKS LIKE BOOKS
制定表空间
db2 create table T1 (c1 int ...) in TS1
db2 create table T2 (c1 float ...) in TS1
删除表
drop table tab_name
添加删除列
db2 => create table test (c1 int)
DB20000I The SQL command completed successfully.
db2 => alter table test add c2 char(8)
DB20000I The SQL command completed successfully.
db2 => alter table test drop c2
DB20000I The SQL command completed successfully.
列的修改及限制
1.修改长度
alter table tab_name alter c1 set data type varchar(20)
2.设置为非空
alter table tab_name alter c1 set not null
create table tab_name (id interger not null)
3.设置默认值
create table tab_name (id integer,name varchar(10) with default 'none')
4.为列创建序列
使用关键字 generated always as identity
create table tab_name (id integer generated always as identity (start with 1,increment by 1))
5.唯一性约束
使用关键字primary key
create table tab_name (id int not null primary key)
使用关键字unique
alter table tab_name add constraint unique (id)
create unique index idx_name on tab_name (id)
6.检查性约束
使用关键字check
ALTER TABLE BOOKS ADD BOOKTYPE CHAR(1) CHECK (BOOKTYPE IN ('F','N') )
7.参照约束
使用关键字references
CREATE TABLE AUTHORS (AUTHORID INTEGER NOT NULL PRIMARY KEY,
LNAME VARCHAR(100),
FNAME VARCHAR(100))
CREATE TABLE BOOKS (BOOKID INTEGER NOT NULL PRIMARY KEY,
BOOKNAME VARCHAR(100),
ISBN CHAR(10),
AUTHORID INTEGER REFERENCES AUTHORS)
- DB2表管理的语句
- DB2日常表,空间管理等部分SQL语句
- 【db2】表空间的管理,创建,维护
- db2的日志管理
- db2的日志管理
- DB2日志的管理
- DB2的权限管理
- DB2表空间管理
- DB2表空间管理
- DB2表空间管理
- DB2 Merge 语句的使用
- DB2 SQL语句的优化
- DB2 查询所有的表名的sql语句
- DB2 单张表 merge语句
- db2使用sql语句查询表的字段类型
- db2 索引,表结构查看的一些语句
- DB2 使用sql语句查询表的字段…
- db2 语句
- VC++ 模拟"CLICK事件"关闭指定窗口
- android binder 机制二(client和普通server)
- OLE DB 访问接口 "SQLNCLI" 返回了消息
- 中缀转后缀求值
- happy every moment
- DB2表管理的语句
- PHP 用正则表达式preg_match_all抓取天气预报
- unicode转码
- IOS的UIView
- 大数计算器
- C#获取从指定的文件路径,获取该文件的图标,然后显示在image里
- DES加密解密(配合GTMBase64)
- 作为成冬青的曾经
- 浅谈工业机器人的运动停止