IF	OBJECT_ID('GLB_USU_RC_MDL_VENDA') IS NULL
BEGIN
	CREATE TABLE [dbo].[GLB_USU_RC_MDL_VENDA](
		[CD_USU] [int] NOT NULL,
		[CD_EMP] [int] NOT NULL,
		[CD_MDL_VD] [int] NOT NULL,	
	 CONSTRAINT [PK_GLB_USU_RC_MDL_VENDA] PRIMARY KEY CLUSTERED 
	(
		[CD_USU] ASC,
		[CD_EMP] ASC,
		[CD_MDL_VD] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY]

 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA]  WITH NOCHECK ADD  CONSTRAINT [FK_GLB_USU_RC_MDL_VENDA_GLB_USU] FOREIGN KEY([CD_USU])
	REFERENCES [dbo].[GLB_USU] ([CD_USU])
	ON UPDATE CASCADE
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA] CHECK CONSTRAINT [FK_GLB_USU_RC_MDL_VENDA_GLB_USU]
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA]  WITH NOCHECK ADD  CONSTRAINT [FK_GLB_USU_RC_MDL_VENDA_RC_MDL_VENDA] FOREIGN KEY([CD_EMP], [CD_MDL_VD])
	REFERENCES [dbo].[RC_MDL_VENDA] ([CD_EMP], [CD_MDL_VD])
	ON UPDATE NO ACTION
	ON DELETE NO ACTION
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA] CHECK CONSTRAINT [FK_GLB_USU_RC_MDL_VENDA_RC_MDL_VENDA]
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA] ADD  CONSTRAINT [DF_GLB_USU_RC_MDL_VENDA_CD_USU]  DEFAULT ((0)) FOR [CD_USU]
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA] ADD  CONSTRAINT [DF_GLB_USU_RC_MDL_VENDA_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]
	 

	ALTER TABLE [dbo].[GLB_USU_RC_MDL_VENDA] ADD  CONSTRAINT [DF_GLB_USU_RC_MDL_VENDA_CD_MDL_VD]  DEFAULT ((0)) FOR [CD_MDL_VD]
	 
END
	 
 