create table xxx (aaa number(10),bbb varchar2(20),ccc date);
新增列:alter table xxx add aaa varchar(100);
注意:在添加表的列名的时候,不允许设置成not null
删除列:alter table xxx drop column aaa;
修改列:alter table xxx modify(aaa varchar(100));
rename old_name to new_name;
drop table xxx;
注意:
①在删除表的时候,经常会遇到多个表关联的情况,多个表关联的时候不能随意删除,需要使用级联删除
②cascade:如果表A、B,A中某个字段与B中某个字段做关联,那么删除表A的时候需要先将表B删除
③set null:在删除的时候,把表的关联字段设置成空
约束:是在表上强制执行的数据校验规则
1、not null:非空约束
插入数据的时候某些列不允许为空
2、unique key:唯一键约束
可以限定某一个列的值是唯一的,唯一键的列一般被用作索引列
3、primary key:主键
非空且唯一,任何一张表,一般情况下最好有主键,用来唯一的标识一行记录
4、foreign key:外键
当多个表之间有关联关系的时候需要使用外键,一个表的某个列的值,依赖于另一张表的某个值
5、check:可以根据用户自己的需求限定某些列的值
重构建表语句:
create table xxx
(aaa number(10) primary key,
bbb varchar2(20) not null,
ccc date unique,
ddd number(3) check(ddd>0 and ddd<126),
eee number(2),
foreign key eee number(eee) references table_name(fff));
1、索引是存在磁盘中的
2、索引的相关操作
创建:create index i_name on emp(ename);
删除:drop index i_name;
原文:https://www.cnblogs.com/lyc-code/p/13510220.html