
IF NOT EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[CustomerGroup]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
	CREATE TABLE [dbo].[CustomerGroup](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Groupname] [varchar](100) NOT NULL,
	CONSTRAINT [PK_CustomerGroup] PRIMARY KEY CLUSTERED 
	(
	[ID] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
	) ON [PRIMARY]
	

IF NOT EXISTS
(
  SELECT SysColumns.Name 
  FROM SysObjects WITH (NOLOCK) 
    INNER JOIN SysColumns WITH (NOLOCK) ON SysColumns.Id = SysObjects.ID 
    AND SysColumns.Name = 'CustomerGroupID'
    WHERE SysObjects.Name = 'Customer'
)
BEGIN
  ALTER TABLE Customer ADD CustomerGroupID INT
  
  ALTER TABLE [dbo].[Customer]  WITH CHECK ADD  CONSTRAINT [FK_Customer_CustomerGroup] FOREIGN KEY([CustomerGroupID])
  REFERENCES [dbo].[CustomerGroup] ([ID])

	
  ALTER TABLE [dbo].[Customer] CHECK CONSTRAINT [FK_Customer_CustomerGroup]
END


