Oracle 基础笔记 1
DDL数据定义语言
create table
eg:
create table stu( s_id number(8) PRIMARY KEY, s_name varchar2(20) not null, s_sex varchar2(8), clsid number(8), constraint u_1 unique(s_name), constraint c_1 check (s_sex in ('MALE','FEMALE')) );
表约束类型有cheque,unique,primary key,not null,foreign key
复制表
eg:
create table test as select * from emp;
注意:复制表不能复制表的线束
创建索引
eg:
create index i_1 on emp(empno asc);
创建同义词
eg:
create synonym mm for emp;
修改表
1.向表中添新字段
ALTER TABLE <table_name> ADD (字段1 类型 [NOT NULL],
字段2 类型 [NOT NULL]
.... );
2.修改表中字段
ALTER TABLE <table_name> modify(字段1 类型,
字段2 类型
.... );
3.删除表中字段
ALTER TABLE <table_name> drop(字段1,
字段2
.... );
4.修改表名称
RENAME <table_name> to <new table_name>;
5.对已经存在的表添加约束
ALTER TABLE <table_name> ADD CONSTRAINT <constraint_name> 约束类型 (针对的字段名);
eg:
Alter table emp add constraint S_F Foreign key (deptno) references dept(deptno);
6.对表里的约束禁用
ALTER TABLE <table_name> DISABLE CONSTRAINT <constraint_name>;
7.对表里的约束重新启用
ALTER TABLE <table_name> ENABLE CONSTRAINT <constraint_name>;
8.删除表中约束
ALTER TABLE <table_name> DROP CONSTRAINT <constraint_name>;
eg:
ALTER TABLE emp drop CONSTRAINT <Primary key>;
drop table emp;
drop index i_1;
drop synonym mm;
DML(数据操作语言)
插入记录
eg:
insert into emp (empno,ename) values(9500,'AA');
create table a as select * from emp where 1=2; insert into a select * from emp where sal>2000;
查询数据
SELECT [DISTINCT] <column1 [as new name] ,columns2,...>
FROM <table1>
[WHERE <条件>]
[GROUP BY <column_list>]
[HAVING <条件>]
[ORDER BY <column_list> [ASC|DESC]]
更新数据
UPDATE table_name set column1=new value,column2=new value,...
WHERE <条件>
删除数据
DELETE FROM <table_name>
WHERE <条件>
DCL数据控制语言
1.授权
GRANT <权限列表> to <user_name>;
2.收回权限
REVOKE <权限列表> from <user_name>
TCL事务控制语言
1.commit 提交
2.rollback 回滚
3.savepoint<savepoint> 保存位置