IF NOT EXISTS (SELECT * FROM SYS.TABLES WHERE NAME= 'EST_ENTID_DOACAO_PRC_BANDEIRA')
BEGIN

	CREATE TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA](
		[CD_EMP] [int] NOT NULL,
		[CD_ENTID] [int] NOT NULL,
		[CD_BANDEIRA] [int] NOT NULL,
		[MSG_IMP_CUPOM_ENTID] [varchar](100) NULL
	 CONSTRAINT [PK_EST_ENTID_DOACAO_PRC_BANDEIRA] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_ENTID] ASC,
		[CD_BANDEIRA]
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
	) ON [PRIMARY]


	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA]  WITH CHECK ADD  CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_EST_ENTID_DOACAO] FOREIGN KEY([CD_EMP], [CD_ENTID])
	REFERENCES [dbo].[EST_ENTID_DOACAO] ([CD_EMP], [CD_ENTID])

	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA] CHECK CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_EST_ENTID_DOACAO]


	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA]  WITH CHECK ADD  CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_PRC_BANDEIRA] FOREIGN KEY([CD_BANDEIRA])
	REFERENCES [dbo].[PRC_BANDEIRA] ([CD_BANDEIRA])

	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA] CHECK CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_EST_ENTID_DOACAO]


	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA]  WITH CHECK ADD  CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_PRC_EMP] FOREIGN KEY([CD_EMP])
	REFERENCES [dbo].[PRC_EMP] ([CD_EMP])
	ON UPDATE CASCADE

	ALTER TABLE [dbo].[EST_ENTID_DOACAO_PRC_BANDEIRA] CHECK CONSTRAINT [FK_EST_ENTID_DOACAO_PRC_BANDEIRA_PRC_EMP]

END