数据库中有两张表,A表主键为自动增长的并且是B表的外键且允许为空。现在要通过编程向B表中插入数据,可是在程序中是不允许给Int类型赋空值的如果不赋值就默认为0。为了解决这个为题最后考虑用存储过程的If Else最方便,具体的存储过程如下
create PROCEDURE [dbo].[P_Form_Control_Info_Add]
@TypeName varchar(20),
@Description varchar(50),
@CtlColSpan int,
@Sort int,
@SourceID int,
@FieldID int,
@TableID int
AS
if @SourceID = 0
begin
INSERT INTO T_Form_Control_Info (
[TypeName],
[Description],
[CtlColSpan],
[Sort],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@FieldID,
@TableID
)
end
else
begin
INSERT INTO T_Form_Control_Info (
[TypeName],
[Description],
[CtlColSpan],
[Sort],
[SourceID],
[FieldID],
[TableID]
) VALUES (
@TypeName,
@Description,
@CtlColSpan,
@Sort,
@SourceID,
@FieldID,
@TableID
)
end
return SCOPE_IDENTITY()
相关文章:
-
2022-12-23
-
2022-12-23
-
2022-02-03
-
2022-12-23
-
2022-12-23
-
2021-05-22
-
2022-12-23
猜你喜欢
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-09-12
-
2021-12-21
-
2022-12-23
-
2022-12-23
相关资源
-
下载
2023-02-17
-
下载
2023-03-03
-
下载
2023-01-09