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

Oracle-基本SQL语句

2016-03-11 14:42 363 查看
--添加一个表
create table TestUser
(
id int primary key ,
name varchar(20) ,
address varchar(20)
)
/*
*设置序列号(标识列)
*/
--第一步:创建SEQUENCE
create   sequence   s_country_id   increment   by   1   start   with   1   maxvalue   999999999;
--第二步:创建一个基于该表的before   insert   触发器,在触发器中使用该SEQUENCE
create   or   replace   trigger   bef_ins_t_country_define
before   insert   on   t_country_define
referencing   old   as   old   new   as   new   for   each   row
begin
select   s_country_id.nextval   into   :new.country_id   from   dual;
end;

--第二步也可以不做
--插入数据的语句这样写insert into   tb...  values(s_country_id.nextval,...);

--查所有
select * from TestUser;
--添加一条记录(根据创建的sequence来添加id)
insert into TestUser (id,name,address) values (s_country_id.nextval,'李四','bbb');
--根据条件删除记录
delete TestUser where id=2
--修改记录
update TestUser set name='小明' where id=1
--删除表
drop table TestUser;
--删除表中记录时释放表空间(仅清空记录)
truncate table TestUser;
--为用户授权
grant select any table to likeyi
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: