IF Not EXISTS(SELECT * FROM sysobjects WHERE name='Shops')
Begin
	CREATE TABLE [dbo].[Shops](
		[Code] [SMALLINT] NOT NULL,
		[Name] [NVARCHAR](MAX) NOT NULL,
		[IsEnabled] [BIT] NOT NULL,
		[IsDefault] [BIT] NOT NULL
	 CONSTRAINT [PK_Shops] PRIMARY KEY CLUSTERED 
	(
	  [Code] ASC
	)
	) ON [PRIMARY]
	ALTER TABLE [dbo].[Shops] ADD  CONSTRAINT [DF_Shops_IsEnabled]  DEFAULT ((1)) FOR [IsEnabled]

	INSERT INTO Shops(Code, Name, IsEnabled, IsDefault )
	SELECT Top 1 '100', Name, 1, 1 FROM dbo.Cooprations
	DECLARE @StoreCode VARCHAR(3)
	SEt @StoreCode = (SELECT TOP 1 Code FROM Shops WHERE IsDefault = 1)
	UPDATE [Manager].dbo.Users SET Store_Code = @StoreCode
	WHERE ISNULL(Store_Code,0) <> @StoreCode
End

