IF NOT EXISTS(SELECT * FROM sys.sysobjects WHERE name ='ShopDetail' and xtype='U')
BEGIN
	CREATE TABLE [dbo].[ShopDetail](
		[Id] [UNIQUEIDENTIFIER] NOT NULL,
		[ShopsCode] [SMALLINT] NOT NULL,
		[SystemName] [VARCHAR](100) NOT NULL,
		[CreatedBy] [SMALLINT] NOT NULL,
		[CreatedOn] [DATETIME] NOT NULL,
	 CONSTRAINT [PK_ShopDetail] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)
	) ON [PRIMARY]

	ALTER TABLE [dbo].[ShopDetail] ADD  CONSTRAINT [DF_ShopDetail_Id]  DEFAULT (NEWID()) FOR [Id]
	ALTER TABLE [dbo].[ShopDetail] ADD  CONSTRAINT [DF_ShopDetail_CreatedOn]  DEFAULT (GETDATE()) FOR [CreatedOn]
	ALTER TABLE [dbo].[ShopDetail]  WITH CHECK ADD  CONSTRAINT [FK_ShopDetail_ShopDetail] FOREIGN KEY([ShopsCode])
	REFERENCES [dbo].[Shops] ([Code])
	ON DELETE CASCADE
	ALTER TABLE [dbo].[ShopDetail] CHECK CONSTRAINT [FK_ShopDetail_ShopDetail]    
END 
