Possible Duplicate:
ALTER TABLE my_table ADD @column INT
Can anyone tell me if it is possible to have a stored procedure that is effectively this:
USE [dbname]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [Schema].[CreateColumn]
@Table varchar(255),
@ColumnName varchar(255)
AS
BEGIN
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
ALTER TABLE [Schema].@Table ADD @ColumnName varchar(255) NULL
ALTER TABLE [Schema].@Table SET (LOCK_ESCALATION = TABLE)
COMMIT
END
GO
Basically, I could pass in a table name and column name and it would create it on that table with proper transactions.