Orcale数据库操作

第二章:数据库操作:
第一节;Oracle 数据库常用指令:

创建用户: create  user  用户名 identified by 密码;

连接用户: conn 用户名/密码;

修改密码: alter user  用户名identified by 密码;

删除用户: drop user 用户名;

删除表单: drop 用户名.表单名;

分配权限: grant  connect to 用户名;

表单权限: grant  all  on表单名 to  用户名;

收回权限: revoke allon 表单名 from 用户名;

权限继承: grant 权限名 on 表单名 to 用户名 with grantoption;

锁定用户: create  profile abc  limit  failed  login attempts 3  password_lock_time 2;

解锁用户: alter user用户名 account unlock;

注释:常用单词:

declare;声明   Revoke:撤销  Profile:简  Account :解释 ,说明Unlock:解锁

第二节:Oracle 表的创建 \删除\修改\添加数据

表的创建:

create table 表的名(

no number(4),

name varchar2(20),

sex char(2),

salary number(7,2)

);

表的查询:

select * from表的名;

添加类:

alter table表单名 add (添加类名number (2));

修改字段的长度:

alter table 表单名 modify (字段名 varchar2(30));

删除一个字段:

alter table 表单名 drop column 删除的字段名;

修改表单名:

rename 原来的单名 to 新的表单名;

删除表单:

drop table 表单名;

查询表的结构:

SQL> desc 查询表的名字;

添加数据;

insert into 表单名 values ('001','李冰','男','001');

部分添加数据;

insert into 表单名(no,name,sex,classid)values ('001','李冰','男','001');

删除表的数据;

delete from 表单名 where no= '序号';

修改表单的数据;

update 表单名 set no ='001' ,name = '王华' where no ='001';

删除表的所有数据和表单结构;

delete from 表单名;

查询时间

set timing on;

第三节:Oracle 约束

约束包括:not null(非空约束)、unique(唯一约束)、primary key(主键)、foreign key(外键)、check

修改约束:

altertable 表单名 modify 数据的列名 not null;

altertable customer add constraint cardunique unique(cardId);

altertable customer add constraint addresscheck check(address in(‘东城’,’西城’));

查询表单的约束:

select* from user_constraints where table_name=upper('&_good');

删除约束:

altertable 表名 drop constraint 约束名称;

删除主键约束的时候,可能有错误,

altertable 表名 drop primary key cascade;

primarykey约束与unique约束的主要区别:

(1)一个表只能创建一个primary key约束,但可根据需要对不同的列创建若干个unique约束。

(2)primary key字段的值不允许为null,而unique字段的值可取null。

primarykey约束与unique约束的相同点:

两者均不允许表中对应字段存在重复值;在创建primary key约束与unique约束时会自动产生索引。

对于primary key约束与unique约束来说,都是由索引强制实现的。


第四节:代码复习

create table student(
no number(4),
name varchar2(20),
sex char(2),
salary number(7,2)
);-- 创建表
select * from student;--查询表
alter table student add (classid number(2));-- 修改字段
alter table student drop column salary;-- 添加字段
alter table student modify (name varchar2(30));--修改字段的值
rename student to stu;-- 修改表的名称
select *from stu;
rename stu to student;
delete from student;
drop table student;-- 删除表单
insert into  student values ('001','李冰','男','001');--全局插入
insert into student (no,name,sex,classid) values ('003','王亏','男','003');-- 局部插入
delete from student where no = '003';-- 删除表单数据
update student set no = '004',  name ='团子' where no = '004';--修改表单数据
alter table student modify name not null;--添加约束
alter table student modify classid check (classid>0);--添加约束
insert into student (no,name,sex,classid) values ('004','null','男','004');--测试约束
alter table student drop constraint name  ; --删除约束
select * from user_constraints where table_name=upper('&_good');-- 查看表的约束条件





  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值