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

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

这里写图片描述

不同的用户间导入数据
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

狂飙的yellowcong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值