码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 常用语法

时间:2014-10-17 23:10:57      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:ar   for   sp   on   ad   ef   size   res   ui   

--创建表空间
create tablespace myschool
datafile ‘D:/ms.dbf‘
size 50M

--创建用户
create user t87 identified by t87;

--授予权限(dba,connect,resource)
grant connect,resource to t87;

--撤销权限
revoke connect,resource from t87;

--修改用户密码
alter user t87 identified by a;

--锁定用户
alter user t87 account lock;

--解锁
alter user t87 account unlock;

--删除用户
drop user t87;

--建表
--主键约束:primary key
--非空约束:not null
--检查约束check (sex in(‘男‘,‘女‘))
--唯一约束:unique
--默认约束:default 20
--外键约束:constraint student_sgroup_fk foreign key(gid) references sgroup(gid)
create table student(
stuid number(8) primary key,
stuname varchar2(50) not null,
sex varchar2(10) check (sex in(‘男‘,‘女‘)),
seat number(8) unique,
age number(8) default 20,
gid number(8) not null,
constraint student_sgroup_fk foreign key(gid) references sgroup(gid)
);

alter table student add constraint student_sgroup_fk foreign key(gid) references sgroup(gid);
create table sgroup(
gid number(8) primary key,
gname varchar2(50) not null
);

--添加列
alter table student add email varchar2(50);

--修改列
alter table student modify email varchar2(100);

--删除列
alter table student drop column email;

--删除表
drop table student purge;

select * from tab;

select * from student for update;
select * from sgroup for update;

-- 创建序列
create sequence stuseq;

select stuseq.nextval from dual;
select stuseq.currval from dual;

select
from biao1 ,biao2
where biao1.ziduan=biao2.ziduan

insert into student
(stuid, stuname, sex, seat, age, gid)
values
(stuseq.nextval, v_stuname, v_sex, v_seat, v_age, v_gid);

Oracle 常用语法

标签:ar   for   sp   on   ad   ef   size   res   ui   

原文地址:http://www.cnblogs.com/heheyixiao/p/4032222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!