IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[MenuWare]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[MenuWare]
(
	[FK_MenuNumber] [int] NOT NULL,
	[InPercent] [bit] NOT NULL,
 CONSTRAINT [PK_MenuWare] PRIMARY KEY CLUSTERED 
(
	[FK_MenuNumber] ASC
)
) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME = 'FK_MenuWare_Ware')
  ALTER TABLE [dbo].[MenuWare]  WITH CHECK ADD CONSTRAINT [FK_MenuWare_Ware] FOREIGN KEY([FK_MenuNumber])
  REFERENCES [dbo].[Ware] ([WareNumber])
  GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE xtype = 'D' AND name = 'DF_MenuWare_InPercent')
  ALTER TABLE [dbo].[MenuWare] ADD  CONSTRAINT [DF_MenuWare_InPercent]  DEFAULT ((1)) FOR [InPercent]

IF NOT EXISTS (SELECT * FROM MenuWare WITH (NOLOCK))
  INSERT INTO MenuWare
    SELECT DISTINCT MenuWareXTab.MenuNumber, 1 FROM MenuWareXTab

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[MenuWareXTab]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
  ALTER TABLE MenuWareXTab ALTER COLUMN Procentage MONEY NULL
