DECLARE @Id Int                               

Select @Id = Id From sysobjects Where Name = 'TblQueue'
IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Id')
  Alter Table dbo.TblQueue Add Id UNIQUEIDENTIFIER Default(NEWID()) NOT NULL;

DECLARE @ColumnName Varchar(20)
Declare @ConstraintName varchar(100)

Select @ColumnName = column_name, @ConstraintName = CONSTRAINT_NAME 
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
AND table_name = 'TblQueue'


IF UPPER(@ColumnName) = 'Queue'    
Begin
  Exec ('ALTER TABLE [dbo].[TblQueue] DROP CONSTRAINT ' + @ConstraintName)
  Alter Table Dbo.TblQueue Add Constraint Pk_Queue Primary Key (Id)    
End




