Oracle 创建表SQL实例

本文档详细介绍了如何使用SQL语句创建用户表,并包含了字段说明、主键约束设置、序列生成及触发器的实现等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
--用户表
--select * from sysuser
--drop table sysuser
--drop sequence seq_sysuser
--insert into sysuser (strcode,strname,blnEnable) values ('admin','admin',1);
--insert into sysuser (sysuserid,strcode,strname,blnEnable) values (999,'zhangsan','zhangsan',1);
*/
-- Create table
create table sysuser
(
  sysuserid NUMBER not null,
  strcode       VARCHAR2(50) not null,
  strname       VARCHAR2(500) not null,
  blnEnable     NUMBER(1) not null,  
  datLastSave   DATE default sysdate not null
);
 
-- Add comments to the columns
comment on column sysuser.sysuserid  is '用户ID';
comment on column sysuser.strcode  is '用户编码';
comment on column sysuser.strname  is '用户名称';
comment on column sysuser.blnEnable  is '启用';
comment on column sysuser.datLastSave  is '最近保存时间';
 
-- Create/Recreate primary, unique and foreign key constraints
alter table sysuser  add constraint PK_sysuser primary key (sysuserid);

--alter table sysuser  add constraint FK_sysuser_RefTableID foreign key (RefTableID)
 -- references RefTable (RefTableID) on delete cascade; 
 
--create sequence
create sequence seq_sysuser
minvalue 1 maxvalue 999999999999999999999999999
start with 1 increment by 1 cache 20;

--create trigger
CREATE OR REPLACE TRIGGER tri_sysuser_bi
BEFORE INSERT ON sysuser FOR EACH ROW
BEGIN
  IF (:new.sysuserid is null) or (:new.sysuserid<0) THEN
     SELECT seq_sysuser.nextval INTO :new.sysuserid FROM DUAL;
  END IF;
END;








 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值