-- 添加secquences
-- Create sequence
create sequence SEQ_TESTID
minvalue 1
maxvalue 10
start with 2
increment by 1
cache 5
cycle
order;
-- 添加表空间
-- 增加表空间大小的四种方法
--/1、Meathod1:给表空间增加数据文件
ALTER TABLESPACE app_data ADD DATAFILE
'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF' SIZE 50M;
--/2、Meathod2:新增数据文件,并且允许数据文件自动增长
ALTER TABLESPACE app_data ADD DATAFILE
'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP04.DBF' SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
--/3、Meathod3:允许已存在的数据文件自动增长
ALTER DATABASE DATAFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF'
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;
--/4、Meathod4:手工改变已存在数据文件的大小
ALTER DATABASE DATAFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP02.DBF'
RESIZE 100M;
-- primary key
-- 1、添加主键
alter table table1 add pk_ primary key(column_key);
-- 2、删除主键
alter table table1 drop constraint pk_;
-- foreign key
-- 1、添加外键
alter table table1 constraint fk_ foreign key(id) references table2(id);
-- 2、删除
alter table table1 drop constraint fk_;
-- 添加字段
-- 1、add column
alter table table1
add (name varchar(20) default "无名" not null);
-- 2、add column more
alter table table1
add (name varchar(20) default "无名" not null)
add (age integer not null);
--字段
-- 1、修改字段约束
alter table table1
modify (name varchar(18) default "无名无姓" not null);
alter table T_ACCT_OPNCLS modify (CLOSE_DATE varchar(8) null);
-- 2、修改字段名
alter table table1 rename column name to name2;
-- 3、删除字段
alter table table1 drop column age;
-- 修改表名
alter table table1 rename to table2;
-- 建立索引
-- 1、单一索引
create index table_index_name on table1(name);
select * from table1 where name='无名';--走索引
-- 2、符合索引
create index table_index_name on table1(name,age);
select * from table1 where name='无名' and age='18';--走索引
-- 3、删除索引
drop index table_index_name;
oracle ddl语句常用语句整理
最新推荐文章于 2023-05-05 08:22:47 发布