sql存储过程中使用 output

时间:2021-08-28 10:44:03

1.sql存储过程中使用 output

CREATE PROCEDURE [dbo].[P_Max]
@a int, -- 输入
@b int, -- 输入
@Returnc int output --输出
AS if (@a>@b)
set @Returnc =@a
else
set @Returnc =@b -- 调用
declare @Returnc int
exec P_Max 2,3,@Returnc output
select @Returnc

 2.Sql Server 增加字段、修改字段、修改类型、修改默认值

 
修改字段名:

  alter table 表名 rename column A to B

修改字段类型:

  alter table 表名 alter column 字段名 type not null

修改字段默认值
  alter table 表名 add default (0) for 字段名 with values   如果字段有默认值,则需要先删除字段的约束,在添加新的默认值,   select c.name from sysconstraints a
  inner join syscolumns b on a.colid=b.colid
  inner join sysobjects c on a.constid=c.id
  where a.id=object_id('表名')
  and b.name='字段名'   根据约束名称删除约束   alter table 表名 drop constraint 约束名   根据表名向字段中增加新的默认值   alter table 表名 add default (0) for 字段名 with values 增加字段:   alter table 表名 add 字段名 type not null default 0 ⑤删除字段:   alter table 表名 drop column 字段名;
 2.nvarchar(max)一坑
  监控邮件中有个变量使用了nvarchar(max),有一天数据多了,总字节有150048,但是总是读出来9000多个。郁闷,查了查,才知道是啥问题。