声明存储过程
CREATE PROCEDURE uptable_field
@tableName nvarchar(64)
AS
BEGIN
declare @sql nvarchar(1500)--声明变量)
declare @sql2 nvarchar(1500)--声明变量)
set @sql = '
alter table '+@tableName+' add UserID int DEFAULT NULL ;
alter table '+@tableName+' add CreatedTime datetime DEFAULT NULL ;
alter table '+@tableName+' add UpdatedTime datetime DEFAULT NULL;
alter table '+@tableName+' add Sort int DEFAULT NULL ;
alter table '+@tableName+' add Deleted bit ;
'
set @sql2='EXECUTE sp_addextendedproperty "MS_Description", "创建者id", "user", "dbo", "table", "'+@tableName+'", "column", "UserID";
EXECUTE sp_addextendedproperty "MS_Description", "创建时间", "user", "dbo", "table", "'+@tableName+'", "column","CreatedTime";
EXECUTE sp_addextendedproperty "MS_Description", "更新时间", "user", "dbo", "table", "'+@tableName+'", "column", "UpdatedTime";
EXECUTE sp_addextendedproperty "MS_Description", "排序", "user", "dbo", "table", "'+@tableName+'", "column", "Sort";
EXECUTE sp_addextendedproperty "MS_Description", "是否删除", "user", "dbo", "table", "'+@tableName+'", "column", "Deleted";
';
exec(@sql) --(执行改sql语句)
exec(@sql2) --(执行改sql语句)
END
调用
EXEC uptable_field "表名"--调用