if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_Group_User]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[Group] DROP CONSTRAINT FK_Group_User
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Group]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Group]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[User]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[User]
GO

CREATE TABLE [dbo].[Group] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[UserId] [int] NULL ,
	[Name] [nvarchar] (50) COLLATE Danish_Norwegian_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[User] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[Navn] [char] (10) COLLATE Danish_Norwegian_CI_AS NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Group] WITH NOCHECK ADD 
	CONSTRAINT [PK_Group] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[User] WITH NOCHECK ADD 
	CONSTRAINT [PK_User] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Group] ADD 
	CONSTRAINT [FK_Group_User] FOREIGN KEY 
	(
		[UserId]
	) REFERENCES [dbo].[User] (
		[id]
	) NOT FOR REPLICATION 
GO

alter table [dbo].[Group] nocheck constraint [FK_Group_User]
GO

