IF Not EXISTS(SELECT * FROM sysobjects WHERE name='TblQueue')
BEGIN 
	CREATE TABLE [dbo].[TblQueue](
		[Queue] [SMALLINT] NOT NULL,
		[DateDay] [SMALLDATETIME] NOT NULL,
		[StartTime] [CHAR](5) NULL,
		[EndTime] [CHAR](5) NULL,
		[Station_Control] [CHAR](2) NULL,
		[QStatus] [CHAR](1) NULL,
		[QSound] [CHAR](1) NULL,
		[User_id] [SMALLINT] NULL,
		[FlagQueue] [CHAR](1) NULL,
		[Position] [TINYINT] NULL,
		[NationalCode] [VARCHAR](10) NULL,
	 CONSTRAINT [PK_TblQueue] PRIMARY KEY CLUSTERED 
	(
		[Queue] ASC,
		[DateDay] ASC
	)
	) ON [PRIMARY]

	ALTER TABLE [dbo].[TblQueue] ADD  CONSTRAINT [DF_TblQueue_Date]  DEFAULT (CONVERT([VARCHAR](10),GETDATE(),(111))) FOR [DateDay]
	ALTER TABLE [dbo].[TblQueue] ADD  DEFAULT ((1)) FOR [QStatus]
	ALTER TABLE [dbo].[TblQueue] ADD  DEFAULT ((0)) FOR [QSound]
	ALTER TABLE [dbo].[TblQueue] ADD  DEFAULT ((0)) FOR [FlagQueue]
	ALTER TABLE [dbo].[TblQueue] ADD  DEFAULT ((0)) FOR [Position]
END 
ELSE
BEGIN
  DECLARE @Id Int                               
  SELECT @Id = Id From sysobjects Where Name = 'TblQueue'
  IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'User_id')
    ALTER Table dbo.TblQueue Add User_id SMALLINT

  SELECT @Id = Id From sysobjects Where Name = 'TblQueue'
  IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'FlagQueue')
    ALTER Table dbo.TblQueue Add FlagQueue CHAR(1) Default(0)

  SELECT @Id = Id From sysobjects Where Name = 'TblQueue'
  IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'Position')
    ALTER Table dbo.TblQueue Add Position TINYINT Default(0)

  SELECT @Id = Id From sysobjects Where Name = 'TblQueue'
  IF not Exists(SELECT * FROM syscolumns WHERE id = @Id and Name = 'NationalCode')
    ALTER Table dbo.TblQueue Add NationalCode VARCHAR(10)
END



