| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 997 人关注过本帖
标题:[求助]一个关于数据库设计的初级问题!!
只看楼主 加入收藏
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 

这个。。。

手上没有中文版的联机丛书,你可以查一下Transaction的工作原理以及作用,当对某Transaction进行Rollback操作的时候,会将相关数值返回到变更前。

触发器里可以按照你需要的条件写判断语句,不符合条件则返回原始状态,并返回错误信息。


2006-04-11 23:43
knlight
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-4-11
收藏
得分:0 
CREATE TRIGGER [t1] ON [dbo].[储户动态信息]
FOR INSERT
*INSTEAD OF INSERT
AS
BEGIN
DECLARE @VALUE TINYINT(1)
DECLARE @JOB MONEY(8)
SELECT @VALUE=信誉
*IF (@VALUE=0) @JOB>=0
*OR IF(@VALUE=1) @JOB>=-50000

*号处出错,为什么?
2006-04-11 23:48
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 

Trigger语法

Create Trigger [TriggerName] on [TableName]
For Insert|Update|Delete
As
....

If语法

If 判断条件 为真执行语句
else 为假执行语句
end


2006-04-11 23:53
knlight
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-4-11
收藏
得分:0 
OK...明天再研究....睡觉了...你有什么联系方法吗??除了在论坛上??当然,是指网上的联系方法....
2006-04-11 23:57
LouisXIV
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:789
专家分:0
注 册:2006-1-5
收藏
得分:0 
MSDN上的这段可以参考一下
C. Use a trigger business rule between the employee and jobs tables

Because CHECK constraints can reference only the columns on which the column- or table-level constraint is defined, any cross-table constraints (in this case, business rules) must be defined as triggers.

This example creates a trigger that, when an employee job level is inserted or updated, checks that the specified employee job level (job_lvls), on which salaries are based, is within the range defined for the job. To get the appropriate range, the jobs table must be referenced.

USE pubs
IF EXISTS (SELECT name FROM sysobjects
      WHERE name = 'employee_insupd' AND type = 'TR')
   DROP TRIGGER employee_insupd
GO
CREATE TRIGGER employee_insupd
ON employee
FOR INSERT, UPDATE
AS
/* Get the range of level for this job type from the jobs table. */
DECLARE @min_lvl tinyint,
   @max_lvl tinyint,
   @emp_lvl tinyint,
   @job_id smallint
SELECT @min_lvl = min_lvl, 
   @max_lvl = max_lvl, 
   @emp_lvl = i.job_lvl,
   @job_id = i.job_id
FROM employee e INNER JOIN inserted i ON e.emp_id = i.emp_id 
   JOIN jobs j ON j.job_id = i.job_id
IF (@job_id = 1) and (@emp_lvl <> 10) 
BEGIN
   RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
   ROLLBACK TRANSACTION
END
ELSE
IF NOT (@emp_lvl BETWEEN @min_lvl AND @max_lvl)
BEGIN
   RAISERROR ('The level for job_id:%d should be between %d and %d.',
      16, 1, @job_id, @min_lvl, @max_lvl)
   ROLLBACK TRANSACTION
END


2006-04-12 00:00
快速回复:[求助]一个关于数据库设计的初级问题!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036258 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved