oracle权限大全序列,ORACLE中的权限设定,建外键,序列,触发器等 .

首先建立了两张表:

create table car_type_t (

typeid numeric(20) not null,

typename varchar(50) null,

constraint PK_CAR_TYPE_T primary key (typeid)

)

create table vehicle_t (

vehicleid numeric(10) not null,

typeid numeric(20) null,

fueltypeid numeric(10) null,

vehiclestatusid numeric(10) null,

vehiclenumber numeric(10) null,

vehiclelength float(10) null,

vehiclewidth float(10) null,

vehiclehigh float(10) null,

vehiclecolor varchar(10) null,

solddat date null,

manufactcomp varchar(100) null,

engineid numeric(20) null,

vehiclephycid numeric(20) null,

width float(5) null,

capaweight float(5) null,

constraint PK_VEHICLE_T primary key (vehicleid)

)

创建两张表之间的关联关系:

alter table vehicle_t

add constraint FK_VEHICLE_RELATIONS_CARTYPE foreign key (typeid)

references car_type_t (typeid)

然后遇到了一些问题:

1.首先是我想让ORACLE中表ID自动增加,

具体实现:

首先建立了一个序列

create sequence cartype_s

increment by 1

start with 10000

nomaxvalue

nocycle;

然后再对这个序列建立了触发器

create or replace trigger car_type_t_trg

before insert or update on car_type_t

for each row

begin

select cartype_s.nextval into :new.typeid from dual;

end;

/在建立出发器的时候遇到了一些问题!就是会报错,"权限不足",于是仔细研究发现:是我建立的该角色没有建触发器的权限:具体建立方法:grant create trigger to vm_user

这样键好后,insert into car_type_t values(232,'test'); 无论第一个字段是多少,最后查询car_type_t是,字段typeid是不断从10000增加的.

2.如何在ORACLE中查看表间关系,及外键关联关系:

select * from all_constraints

where constraint_type = 'R'

and owner = 'CARMEN'

select * from all_cons_columns

where owner = 'CARMEN'

and constraint_name = 'PK_CAR_TYPE_T'

此两行语句就可以查出表中的FK对应的PK,和PK对应的表名称.

3.删除表的时候需要先删除外键

alter table VEHICLE_T

drop constraint FK_VEHICLE_RELATIONS_CARTYPE

drop table car_type_t才可以做到

4.查询触发器

Select * from All_Triggers

where owner='CARMEN'

5.删除序列

drop sequence cartype_s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值