Oracle常用的命令

常用的命令,一时不知道从哪开始说起。

算了,还是从开始创建用户说起:

  • 用超级管理员连接数据库:

  • connect sys/admin as sysdba;

  • 开始创建用户

  • create user zhangxiangfeng identified by zhangxiangfeng;

  • 给用户授权(connect,resource,dba )

  • grant connect,resource to zhangxiangfeng;

  • 将某一个表授权给用户

  • 实例:grant select,insert,update,delete on 表名 to 用户名

  • 显示当前连接的用户

  • show user;

  • 修改用户密码以及解锁

  • alter user scott identified by tiger account unlock;

  • 使用创建好的用户链接数据库

  • connect zhangxiangfeng/zhangxiangfeng;

  • 数据库信息的导入与导出

  • --导出(dos下执行)
    exp scott/tiger file=d:\daochu.dmp owner=(scott)
    --导入(dos下执行)
    imp zxf/zxf file=d:\daochu.dmp fromuser=scott touser=zxf

  • 修改表名

  • ALTER TABLE old_table_name RENAME TO new_table_name;(大写为系统命令)

  • 添加列

  • alter table 表名 add 列名 varchar(40);

  • 修改列名

  • alter table 表名 rename column旧的字段名 to 新的字段名名;

  • 修改字段类型

  • alter table 表名 modify 字段名 数据类型;

  • 创建外键
  • alter table 外键表 add contraint foreign key(外键字段) 外键名称 references 主键表(依赖字段名);

  • 删除结构用 drop 删除数据用delete

创建表的sql常用sql语句就不用写了把,还是附个吧。

drop table t_10_01_student;
drop table t_10_01_class;
drop table t_10_01_grade;
--用了系统函数sys_guid 会生成32的全球唯一字符串!!!
create table t_10_01_grade(
  id varchar2(32) default sys_guid() primary key ,
  gname varchar2(50) not null
);

create table t_10_01_class(
  id varchar2(32) default sys_guid() primary key ,
  cname varchar2(50) not null,
  gid varchar2(32),
  foreign key (gid) references t_10_01_grade(id)--建立外键方式1
);

create table t_10_01_student(
  id varchar2(32) default sys_guid() primary key ,
  sname varchar2(50) not null,
  sage number(2) not null,
  cid varchar2(32) references t_10_01_class(id)--建立外键方式2
);
select * from t_10_01_grade;
select * from t_10_01_class;
select * from t_10_01_student;
/

如有问题,请留言交流。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一缕阳光直射你的心扉

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

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

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

打赏作者

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

抵扣说明:

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

余额充值