---------------------------------------------------表操作-------------------------------------------------------
1.表的创建:
create table table_name(column_name datatype[,column_name datatype])
2.表数据的插入:
insert into table_name values(column_instance)
3.更新数据:
update table_name set column_instance=? where column_name=?
4.查询数据:
select * from table_name where condition1 group by column_name1... having.... order by column_name[desc,[asc]]
5.删除数据:
delete from table_name where column_name1=?
6.在表空间上建立表:
create table tablename(column_name,datatype)tablespace tablespace_name
7.oracle中提供5种约束:
Check,not null,unique,primary key,foreign key
(a)check约束
Create table policies(policy_id number ,holder_name varchar2(40),gender varchar2 (1) constraint chk_gender check (gender in ('M','F'),marital_status varchar2 (1),
date_of_birth date ,constraint chk_marital check (marital_status in('S','M','D','W')));
(b)not null约束
Create table policies(policy_id number ,holder_name varchar2 (40) not null,gender varchar2(1),marital_status varchar2(1),date_of_birth date not null);
对于not null的alter table语句与其他约束稍微有点不同。Alter table policies modify holder_name not null
(c)unique约束
create table emp(eid int ,ename varchar2(10),constraint uq unique(eid,ename))
create table emp (eid int ,ename varchar(10))
alter table emp add constraint pk primary key(eid,ename);
8。
(a)添加新列
alter table table_name add column_name datatype [constraint][constraint_name]
(b) 添加新列并指定默认值
alter table table_name add column_name datatype default expression
alter table table_name drop column column_name--删除列
alter table table_name modify column_name datatype--修改类属性
alter table table_name disable constraint constraint_name--禁用约束
alter table table_name enable constraint constraint_name--启用约束
alter table table_name add constraint constraint_name constraint_type(column_name)--添加约束
alter table table_name drop constraint constraint_name [cascade]--删除约束
--组合主健(可以用多个列组合成一个主健)
alter table table_name add constraint constraint_name primary key (column_name, column_name...)