FOREIGN KEY Constraint Keywords
FOREIGN KEY: Defines the column in the child table at the table-constraint level
REFERENCES:> ON DELETE CASCADE: Deletes the dependent rows in the child table when a row in the parent table is deleted
ON DELETE SET NULL: Converts dependent foreign key values to null
CREATE TABLE employees(
employee_id NUMBER(6),
last_name VARCHAR2(25) NOT NULL,
email VARCHAR2(25),
salary NUMBER(8,2),
commission_pct NUMBER(2,2),
hire_date DATE NOT NULL,
...
department_id NUMBER(4),
CONSTRAINT emp_dept_fk FOREIGN KEY (department_id)
REFERENCES departments(department_id),
CONSTRAINT emp_email_uk UNIQUE(email));
创建表 示例:
CREATE TABLE teach_emp (
empno NUMBER(5) PRIMARY KEY,
ename VARCHAR2(15) NOT NULL,
job VARCHAR2(10),
mgr NUMBER(5),
hiredate DATE DEFAULT (sysdate),
photo BLOB,
sal NUMBER(7,2),
deptno NUMBER(3) NOT NULL
CONSTRAINT admin_dept_fkey REFERENCES
departments(department_id));
创建表用子查询
CREATE TABLE dept80
AS SELECT employee_id, last_name,
salary*12 ANNSAL,
hire_date FROM employees WHERE department_id = 80; ALTER
Use the> Add a new column
Modify an existing column definition
Define a default value for the new column
Drop a column
Rename a column
Change table to read-only status
语法
alter table test
add (column datatype, ......) 添加列
modify (column datatype, ......) 变更列
drop (column datatype, ......) 删除列
set unused column colum_name 不可用列
drop unused columns
ORACLE修改列名与列类型
--修改列名
alter table 表名 rename column 旧列名 to 新列名;
--修改列类型
alter table 表名 modify (列名varchar(255));
删除表的一列:
alter table 表名 drop column 列名;
给表增加一列:
alter table 表名 add 列名 类型 default 值 < not null>;
案列:
ALTER TABLE TABLE_ABC ADD COLUMN_AAA NUMBER DEFAULT 10000 NOT NULL ; DROP
drop table test;
了解 :alter table table_name read only;
改表名:alter table table_name1 rename to table_name2;
改列名:alter table table_name rename oldcol column1 to column2;
看约束(数据字典)select from user_constraints where table_name='TEST' ;
查看回收站:select from user_recyclebin;