生成表
--临时表,存在于事务范围或会话范围,供全体用户使用
create global temporary table temp_emp
(empno number,
ename varchar2(10));
create table emp_copy as select * from emp where deptno = 10;
create table emp_copy (empno, sal) as select empno, sal from emp where deptno = 10;
更改表结构
--添加新列
alter table emp add (hire_date date);
--修改数据类型(增加容易,减少难)
alter table prod modify (lastname varchar(25));
--减少
create table test (col2) as select col2 from tester;
update tester set col2 = null;
alter table tester modify (col2 varchar2(5));
--删除
alter table emp set unused column salary;
alter table emp drop unused columns;
alter table emp drop column salary;
--截断表
truncate table tester;
约束:在列数据定义后添加
唯一性约束自动生成索引(主键和唯一约束)
--主键约束(列约束和表约束)
constraint pk_emp primary key (empid)
--外键约束
references tablename (table_column) on delete set null | cascade
--唯一约束
unique
--NULL约束和检查约束
not null | check (salary <= 250000)
--临时表,存在于事务范围或会话范围,供全体用户使用
create global temporary table temp_emp
(empno number,
ename varchar2(10));
create table emp_copy as select * from emp where deptno = 10;
create table emp_copy (empno, sal) as select empno, sal from emp where deptno = 10;
更改表结构
--添加新列
alter table emp add (hire_date date);
--修改数据类型(增加容易,减少难)
alter table prod modify (lastname varchar(25));
--减少
create table test (col2) as select col2 from tester;
update tester set col2 = null;
alter table tester modify (col2 varchar2(5));
--删除
alter table emp set unused column salary;
alter table emp drop unused columns;
alter table emp drop column salary;
--截断表
truncate table tester;
约束:在列数据定义后添加
唯一性约束自动生成索引(主键和唯一约束)
--主键约束(列约束和表约束)
constraint pk_emp primary key (empid)
--外键约束
references tablename (table_column) on delete set null | cascade
--唯一约束
unique
--NULL约束和检查约束
not null | check (salary <= 250000)