您的位置:首页 > 数据库 > Oracle

Oracle之表创建及常用操作-yellowcong

2017-11-30 21:28 295 查看
oracle常用的建表操作中,需要注意添加索引,还有备注的添加,最后还要注意数据库表的导入到处操作。导出导入命令不是sql语句,而是直接调用了是 Oracle的bin目录下 exp和imp两个工具类



创建表

create table sys_yellowcong_user(
username varchar2(32) primary key ,
age number(3) check (age >=0 and age<=200),
nickname varchar2(32),
email varchar2(64)  not null
)


添加索引

-- 建立索引
-- user_index 相当于索引表
-- create  index 索引名 on 表明 (列明1,列明2);
create index user_index on yellowcong.sys_user (username,nickname);


添加备注

--添加注释
comment on table sys_user is '用户信息表';
comment on column sys_user.username is '用户名';
comment on column sys_user.age is '年龄';
comment on column sys_user.nickname is '用户别名';
comment on column sys_user.email is '邮箱';


修改表结构

-- 修改表字段不为空
alter table sys_yellowcong_user modify email not null;

-- 添加唯一约束
alter table yellowcong.sys_yellowcong_user add constraint nickname unique(nickname);

-- 删除为一键
alter table customer drop primary key;

-- 强制表唯一键 删除
alter table customer drop primary key cascade;

--添加和修改check约束
alter table customer add constraint address check(address  in ('中国','美国','英国'));


删除表

-- yellowcong 表示的是namespace(表空间)
drop table yellowcong.sys_yellowcong_user


导出数据库

下面是常用的导出,不过在上面命令后面 加上 compress=y 就可以了对数据进一步压缩

-- 直接在cmd执行,不需要进入到sqlplu
-- yellowcong(用户名)/(yellowcong)密码@localhost:1521ORCL(数据库实例)
exp yellowcong/yellowcong@ORCL file=E:\test.dmp full=y

--导出指定表
exp yellowcong/yellowcong@ORCL file=E:\test.dmp tables=(table1,table2)

--导出指定用户所拥有的的表
exp yellowcong/yellowcong@ORCL file=d:\daochu.dmp owner=(system,sys)

--导入带条件的表
exp system/manager@ORCL file=d:\daochu.dmp tables=(table1) query=\" where filed1 like  '00%'\"




导入数据库

--导入dmp  到Test的实例中 ignore=y  表示对已经存在的表不进行导入
imp yellowcong/yellowcong@ORCL  file=d:\test.dmp  ignore=y

--导入指定表
imp yellowcong/yellowcong@ORCL  file=d:\test.dmp  tables=(table1)

--不同用户间导入 log 是日志
imp test/test@ORCL fromuser=yellowcong touser=test file=E:\test.dmp log=E:\test.log;

--相同用户导入数据 , 就不需要使用 formuser 和touser了
imp test/test@ORCL  file=E:\test.dmp log=c:\test.log full=y




不同的用户间导入数据

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: