oracle ddl语句常用语句整理

-- 添加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;
  
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值