alter table
1.更改字段的類型:alter table 表名 modify(字段名 字段類型);
alter table student modify(age char(10));
2.更改表名:alter table 表名 rename to 新表名;
alter table student rename to re_student;
3.更改字段名:alter table 表名 rename column 字段名 to 新字段名;
alter table student rename column age to re_age;
4.增加字段:alter table 表名 add(字段名 字段類型);
alter table student add(note varchar2(200));
5.刪除字段:alter table 表名 drop(字段名);
alter table student drop age;
6.增加約束:
alter table student add constraint pk_student primary key(id);
alter table student add constraint uc_student unique(id);
alter table student add constraint fk_student foreign key(id_class) references class(id);
alter table student add constraint chk_student check(id>0);
7.刪除約束:
alter table student drop constraint 約束名;
8.設置字段默認值:
alter table 表名 alter column 字段名 set default '默認值';
9.撤銷default約束:alter table 表名 alter column 字段名 drop default;
10.增加視圖
create view 視圖名 as
select 字段名1,字段名2…… from 表名 where 字段名1<100;
11.撤銷視圖
drop view 視圖名
12.增加索引
create index 索引名 on 表名(字段名);
create index idx_student on student(name);
13.撤銷索引
drop index 索引名;
14.自增(oracle需創建序列)
create sequence stu_sequence
minvalue 1
start with 1
increment by 1
cache 10;
insert into student(id,age) values (stu_sequence.nextval,age);