首页 | 联系我们 | 叶凡网络官方QQ群:323842844
游客,欢迎您! 请登录 免费注册 忘记密码
您所在的位置:首页 > 开发语言 > DataBase > 正文

oracle中序列和触发器的结合使用

作者:cocomyyz 来源: 日期:2013-06-26 10:58:32 人气:8 加入收藏 评论:0 标签:database

注意创建触发器之后的"/"符号!

-- ----------------------------
-- Table structure for ReportDesigns
-- ----------------------------
CREATE TABLE ReportDesigns (
ReportDesignID NUMBER(10) NOT NULL PRIMARY KEY,
Name VARCHAR2(255) NOT NULL,
Description VARCHAR2(500) NOT NULL,
FileContent BLOB NOT NULL,
CreatorRoles VARCHAR2(500) NOT NULL,
ViewerRoles VARCHAR2(500) NOT NULL,
ParameterKeys VARCHAR2(500) NOT NULL,
CreatedTimestamp TIMESTAMP NOT NULL
);

-- ----------------------------
-- Sequence for ReportDesigns
-- ----------------------------
CREATE SEQUENCE ReportDesigns_seq MINVALUE 1 MAXVALUE 9999999999 START WITH 1 INCREMENT BY 1 NOCACHE;

-- ----------------------------
-- Trigger for ReportDesigns
-- ----------------------------
CREATE TRIGGER ReportDesigns_tri BEFORE INSERT ON ReportDesigns FOR EACH ROW WHEN (NEW.ReportDesignID IS NULL)
BEGIN
SELECT ReportDesigns_seq.NEXTVAL INTO :NEW.ReportDesignID FROM DUAL;
END;
/


-- ----------------------------
-- Table structure for ReportResults
-- ----------------------------
CREATE TABLE ReportResults (
ReportID NUMBER NOT NULL PRIMARY KEY,
ReportDesignID NUMBER NOT NULL,
UserID VARCHAR2(20) NOT NULL,
ReportParameters VARCHAR2(500) NOT NULL,
Remarks VARCHAR2(500) NOT NULL,
GeneratedTimestamp TIMESTAMP NOT NULL,
CONSTRAINT FK_ReportResults_ReportDesigns
FOREIGN KEY (ReportDesignID) REFERENCES ReportDesigns(ReportDesignID)
);

-- ----------------------------
-- Sequence for ReportResults
-- ----------------------------
CREATE SEQUENCE ReportResults_seq MINVALUE 1 MAXVALUE 9999999999 START WITH 1 INCREMENT BY 1 NOCACHE;

-- ----------------------------
-- Trigger for ReportResults
-- ----------------------------
CREATE TRIGGER ReportResults_tri BEFORE INSERT ON ReportResults FOR EACH ROW WHEN (NEW.ReportID IS NULL)
BEGIN
SELECT ReportResults_seq.NEXTVAL INTO :NEW.ReportID FROM DUAL;
END;
/


-- ----------------------------
-- Table structure for Document
-- ----------------------------
CREATE TABLE Document (
DocumentID NUMBER NOT NULL PRIMARY KEY,
Name VARCHAR2(255) NOT NULL,
Description VARCHAR2(500) DEFAULT NULL,
FileContent BLOB NOT NULL,
FileFormat VARCHAR2(20) NOT NULL,
AccessRoles VARCHAR2(500) NOT NULL,
ParameterKeys VARCHAR2(500) DEFAULT NULL,
UserID VARCHAR2(20) NOT NULL,
CreatedTimestamp TIMESTAMP NOT NULL
);

-- ----------------------------
-- Sequence for Document
-- ----------------------------
CREATE SEQUENCE Document_seq MINVALUE 1 MAXVALUE 9999999999 START WITH 1 INCREMENT BY 1 NOCACHE;

-- ----------------------------
-- Trigger for Document
-- ----------------------------
CREATE TRIGGER Document_tri BEFORE INSERT ON Document FOR EACH ROW WHEN (NEW.DocumentID IS NULL)
BEGIN
SELECT Document_seq.NEXTVAL INTO :NEW.DocumentID FROM DUAL;
END;
/


本文网址:http://www.mingyangnet.com/html/database/68.html
读完这篇文章后,您心情如何?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
上一篇:没有资料
更多>>网友评论
发表评论
编辑推荐
  • 没有资料