USE [AIS_S3]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Groups]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Groups](
	[GroupNo] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [varchar](255) NOT NULL,
	[LastModified] [datetime] NOT NULL,
 CONSTRAINT [PK_Groups] PRIMARY KEY CLUSTERED 
(
	[GroupNo] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupUsers]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupUsers](
	[GroupUserNo] [int] IDENTITY(1,1) NOT NULL,
	[GroupNo] [int] NOT NULL,
	[UserNo] [int] NOT NULL,
	[LastModified] [datetime] NOT NULL,
 CONSTRAINT [PK_GroupUsers] PRIMARY KEY CLUSTERED 
(
	[GroupUserNo] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


if NOT Exists(select * from sys.columns where Name = N'GroupVending'   
                and Object_ID = Object_ID(N'dbo.MachineBins')) 
 
begin 
 
ALTER TABLE [dbo].MachineBins
ADD GroupVending bit DEFAULT 0 NOT NULL
end 

if NOT Exists(select * from sys.columns where Name = N'LimitVending'   
                and Object_ID = Object_ID(N'dbo.MachineBins')) 
 
begin 
 
ALTER TABLE [dbo].MachineBins
ADD LimitVending bit DEFAULT 0 NOT NULL
end 



if NOT Exists(select * from sys.columns where Name = N'GroupNo'   
                and Object_ID = Object_ID(N'dbo.MachineBins')) 
 
begin 
 
ALTER TABLE [dbo].MachineBins
ADD GroupNo int DEFAULT 0 NOT NULL
end 

if NOT Exists(select * from sys.columns where Name = N'ItemPerDay'   
                and Object_ID = Object_ID(N'dbo.MachineBins')) 
 
begin 
 
ALTER TABLE [dbo].MachineBins
ADD ItemPerDay int DEFAULT 0 NOT NULL
end 


if NOT Exists(select * from sys.columns where Name = N'ItemPerWeek'   
                and Object_ID = Object_ID(N'dbo.MachineBins')) 
 
begin 
 
ALTER TABLE [dbo].MachineBins
ADD ItemPerWeek int DEFAULT 0 NOT NULL
end 

