Oracle_071_lesson_p11
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle_071_lesson_p11相关的知识,希望对你有一定的参考价值。
DDL数据定义语言
对象:表table , 视图 view , 序列 sequence , 索引 index , 同义词 synonym
CREATE
CREATE TABLE dept
(deptno NUMBER(2),
dname VARCHAR2(14),
loc VARCHAR2(13),
createdate DATE DEFAULT SYSDATE);
表:字母开头,1-30个字符长度,名称范围 大小写 数字 $ 和# ,不要用关键字作表名,不能和其他表名冲突;
show paramenter def;
如def......_creation 为true ,则不分配空间; 为false,则分配空间;
constraints 约束
NOT NULL 非空
UNIQUE 唯一
PRIMARY KEY 主键
FOREIGN KEY 外键
CHECK 检查
列级别约束
如:
CREATE TABLE employees(
employee_id number(6)
CONSTRAINT pk_emp_emp_id PRIMARY KEY,
first_name varchar2(20),
...);
表级别约束
如:
CREATE TABLE employees(
employee_id number(6),
first_name varchar2(20),
......
job_id varchar2(10) NOT NULL,
CONSTRAINT pk_emp_emp_id
PRIMARY KEY(EMPLOYEE_ID));
如 唯一键约束
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,
...
CONSTRAINT emp_email_uk UNIQUE(email));
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 ALTER TABLE statement to:
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
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_recyclebin;
以上是关于Oracle_071_lesson_p11的主要内容,如果未能解决你的问题,请参考以下文章