SELECT @FieldID = FieldID, @Name = [Name], @DataType = DataType
FROM Inserted
if not exists (SELECT * FROM syscolumns
where id=object_id('Customeres')
AND name=@Name)
BEGIN
SET @SQL = 'ALTER table Customeres add ' + @Name + ' '
+ @DataType + '(64) NULL'
EXEC (@SQL)
END
PRINT @Name + ',' + @DataType
4 演示,在查询分析中执行
Insert into Fields ([name], DataType) values ('name', 'varchar') 参考来源:
Add a column to a table unless it already exists
Using Triggers In MS SQL Server