IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='GLB_AGEND_LOJA_PRC_FILIAL') 
BEGIN
	CREATE TABLE [DBO].[GLB_AGEND_LOJA_PRC_FILIAL](
		[CD_AGEND] [INT]  NOT NULL,
		[CD_EMP] [INT]  NOT NULL,
		[CD_FILIAL] [INT]  NOT NULL,
	 CONSTRAINT [PK_GLB_AGEND_LOJA_PRC_FILIAL] PRIMARY KEY CLUSTERED 
	(
		[CD_AGEND] ASC,
		[CD_EMP] ASC,
		[CD_FILIAL] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]

	ALTER TABLE [dbo].[GLB_AGEND_LOJA_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_GLB_AGEND_LOJA_PRC_FILIAL_GLB_AGEND_LOJA] FOREIGN KEY([CD_AGEND])
	REFERENCES [dbo].[GLB_AGEND_LOJA] ([CD_AGEND])

	ALTER TABLE [dbo].[GLB_AGEND_LOJA_PRC_FILIAL]  WITH CHECK ADD  CONSTRAINT [FK_GLB_AGEND_LOJA_PRC_FILIAL_PRC_FILIAL] FOREIGN KEY([CD_EMP], [CD_FILIAL])
	REFERENCES [dbo].[PRC_FILIAL] ([CD_EMP], [CD_FILIAL])

END


