50分求助insert,update时保持数据一致性的问题,急!
表的内容:name:graduationdesign
ThemeID int identity(0,1)
Chapter tinyint ,
Sections tinyint,
Type char(10),
Difficulty char(10),
BlankCount tinyint,
Mark tinyint,
PitchedOnTime tinyint,
ThemeContent text,
BeGraphic bit,
GraphicsFile image
我在这个表中建了一个选题系统的大体表
其中BeGraphic字段 表示该题有无图(1有,0无)
GraphicsFile字段存图
二者都可以为空
但我想在insert 和 update时
1.如果用户把BeGraphic置为1 那么GraphicsFile不能为空
2. 如果用户把BeGraphic置为0 那么GraphicsFile必须为空
3.GraphicsFile为空时 BeGraphic必须置为0
4.GraphicsFile不为空时 BeGraphic必须置为1
请问如何写个存储过程或者触发器来实现对用户输入以上情况时作相应的控制啊
问题点数:50、回复次数:4Top
1 楼skeeterLa(英俊的大米虫)回复于 2005-04-03 19:12:50 得分 10
程序中可以控制。Top
2 楼zchengdw(zcheng)回复于 2005-04-03 19:20:53 得分 0
我是写好存储过程然后让程序开发调用的
他只负责调用和参数传递Top
3 楼skeeterLa(英俊的大米虫)回复于 2005-04-03 19:24:04 得分 40
CREATE PROCEDURE dbo.saveUP_graduationdesign
@ThemeID int identity(0,1)
@Chapter tinyint ,
@Sections tinyint,
@Type char(10),
@Difficulty char(10),
@BlankCount tinyint,
@Mark tinyint,
@PitchedOnTime tinyint,
@ThemeContent text,
@BeGraphic bit,
@GraphicsFile image,
@tag bit -----判断是insert 还是update
declare @Etag bit
set @etag=1
if @BeGraphic=1
begin
if @GraphicsFile is null
begin
set @etag=0
end
end
else
begin
if @GraphicsFile is not null
begin
set @etag=0
end
end
……………
end
if @etag=1 then
-----执行 update 或 insert
else
begin
--------返回参数 提示用户输入不符合条件
end
Top
4 楼zchengdw(zcheng)回复于 2005-04-06 11:05:57 得分 0
多谢楼上啊 辛苦了
Top




