表基本信息修改
2015-04-17 14:02
176 查看
示例操作如下
--班级信息表
create table t_class_info(
classno number(3) primary key,
classname varchar2(10),
classplace varchar2(13)
);
--学生信息表
create table t_student_info(
stuno number(3),
classno number(3),
stuname varchar2(10),
stusex char(1),
stucontect number(11),
stuadd varchar2(50),
studetailinfo varchar2(100)
);
--重命名表
alter table t_class_infot rename to t_class_info
--修改列名
alter table t_class_info rename column classplace to location;
--添加主键约束
alter table t_student_info add constraint pk_stu_no primary key(stuno);
--添加外键约束
alter table t_student_info add constraint fk_classno foreign key(classno) references t_class_info(classno);
--添加check约束
alter table t_student_info add constraint ck_stu_info check (stusex in ('f','m'));
alter table ttt add constraint index_age check (age>0 and age<50)
--添加not null约束
alter table t_student_info modify stucontect constraint not_null_info not null;
--添加unique约束
alter table t_student_info add constraint uq_stu_contect unique(stucontect);
--添加default约束
alter table t_student_info modify stusex char(2) default'm';
--增加列
alter table t_student_info add stuid varchar2(18);
alter table t_student_info add stuage date default sysdate not null;
--删除列
alter table t_student_info drop column studetailinfo;
--修改列的长度,长度只能由小改成大,如果要改小,则要删除该字段下的值
alter table t_class_info modify classplace varchar2(50);
--修改列的精度
alter table t_student_info modify stuno number(2);
--修改列的数据类型
alter table t_student_info modify stusex char(2);
--修改列的默认值
alter table t_student_info modify stuage default sysdate+1;
--禁用约束
alter table t_student_info disable fk_classno;
--启用约束
alter table t_student_info enable fk_classno;
--删除约束,如果有外键约束则要先删除外键表中的
alter table t_student_info drop fk_classno;
--延迟约束
alter table t_student_info add constraint fk_classno foreign key(classno)
references t_class_info(classno)
deferrable initially deferred;
--向表中添加注释
comment on table t_student_info is '学生表';
--向列添加注释
comment on column t_student_info.stuname is '学生姓名';
comment on column t_class_info.classname is '班级';
--清除表中所有数据
truncate table t_student_info;
--删除表
drop table t_student_info;
--删除表不经过回收站
drop table t_student_info purge;
--闪回被删除的表
flashback table t_student_info to before drop;
--班级信息表
create table t_class_info(
classno number(3) primary key,
classname varchar2(10),
classplace varchar2(13)
);
--学生信息表
create table t_student_info(
stuno number(3),
classno number(3),
stuname varchar2(10),
stusex char(1),
stucontect number(11),
stuadd varchar2(50),
studetailinfo varchar2(100)
);
--重命名表
alter table t_class_infot rename to t_class_info
--修改列名
alter table t_class_info rename column classplace to location;
--添加主键约束
alter table t_student_info add constraint pk_stu_no primary key(stuno);
--添加外键约束
alter table t_student_info add constraint fk_classno foreign key(classno) references t_class_info(classno);
--添加check约束
alter table t_student_info add constraint ck_stu_info check (stusex in ('f','m'));
alter table ttt add constraint index_age check (age>0 and age<50)
--添加not null约束
alter table t_student_info modify stucontect constraint not_null_info not null;
--添加unique约束
alter table t_student_info add constraint uq_stu_contect unique(stucontect);
--添加default约束
alter table t_student_info modify stusex char(2) default'm';
--增加列
alter table t_student_info add stuid varchar2(18);
alter table t_student_info add stuage date default sysdate not null;
--删除列
alter table t_student_info drop column studetailinfo;
--修改列的长度,长度只能由小改成大,如果要改小,则要删除该字段下的值
alter table t_class_info modify classplace varchar2(50);
--修改列的精度
alter table t_student_info modify stuno number(2);
--修改列的数据类型
alter table t_student_info modify stusex char(2);
--修改列的默认值
alter table t_student_info modify stuage default sysdate+1;
--禁用约束
alter table t_student_info disable fk_classno;
--启用约束
alter table t_student_info enable fk_classno;
--删除约束,如果有外键约束则要先删除外键表中的
alter table t_student_info drop fk_classno;
--延迟约束
alter table t_student_info add constraint fk_classno foreign key(classno)
references t_class_info(classno)
deferrable initially deferred;
--向表中添加注释
comment on table t_student_info is '学生表';
--向列添加注释
comment on column t_student_info.stuname is '学生姓名';
comment on column t_class_info.classname is '班级';
--清除表中所有数据
truncate table t_student_info;
--删除表
drop table t_student_info;
--删除表不经过回收站
drop table t_student_info purge;
--闪回被删除的表
flashback table t_student_info to before drop;
相关文章推荐
- 全志a20修改设备基本信息--> 修改 build.prop
- VTK修炼之道18:图像基本操作_图像信息的访问与修改(vtkImageChangeInformation)
- 修改学生信息窗体——基本数据该从哪里读入
- 修改学生信息窗体——基本数据该从哪里读入
- [易飞]其中某个品号基本信息不允许修改补货政策
- 在Ms Sql中用alert table 修改表基本信息、表结构等
- [易飞]其中某个品号基本信息不允许修改补货政策
- http协议5---响应信息的基本格式(实现对请求信息的修改)
- 刚想起 微信修改基本配置信息
- 42-IO流(Properties集合的-基本功能). 44-IO流(Properties集合的-store方法) load方法 45-IO流(Properties集合的-修改配置信息)
- S3C6410移植u-boot-2010.3(2)基本的启动信息修改
- usermod命令_Linux usermod 命令用法详解:用于修改用户的基本信息
- S3C6410移植u-boot-2010.3(2)基本的启动信息修改
- VTK修炼之道17:图像基本操作_图像信息的访问与修改(vtkImageData)
- openwrt 修改flash中mac地址信息的基本方法
- 微信修改基本配置信息
- 微信开发第5章 通过accesstoken获取用户基本信息并修改用户备注
- ThinkPHP 3 的CURD管理用户信息 修改和删除
- Java课程设计-学生基本信息管理 201521123036
- 使用Java应用程序导出Mysql 数据库里面的基本表信息