IF  NOT EXISTS (SELECT * FROM sys.objects 
					WHERE object_id = OBJECT_ID(N'RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC') 
					AND type in (N'U')) 
BEGIN
CREATE TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC](
	[CD_CTR_LOTE] [int] NOT NULL,
	[CD_EMP] [int] NOT NULL,
	[CD_FILIAL] [int] NOT NULL,
	[CD_VD] [int] NOT NULL,
	[CD_CTR] [int] NOT NULL,
	[CD_CTR_NCC] [int] NOT NULL,
 CONSTRAINT [PK_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] PRIMARY KEY CLUSTERED 
(
	[CD_CTR_LOTE] ASC,
	[CD_EMP] ASC,
	[CD_FILIAL] ASC,
	[CD_VD] ASC,
	[CD_CTR] ASC,
	[CD_CTR_NCC] 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].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_CTR_LOTE]  DEFAULT ((0)) FOR [CD_CTR_LOTE]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_EMP]  DEFAULT ((0)) FOR [CD_EMP]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_FILIAL]  DEFAULT ((0)) FOR [CD_FILIAL]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_VD]  DEFAULT ((0)) FOR [CD_VD]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_CTR]  DEFAULT ((0)) FOR [CD_CTR]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] ADD  CONSTRAINT [DF_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_CD_CTR_NCC]  DEFAULT ((0)) FOR [CD_CTR_NCC]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC]  WITH CHECK ADD  CONSTRAINT [FK_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_PDV_VD_DEV_NCC] FOREIGN KEY([CD_CTR_NCC])
REFERENCES [dbo].[PDV_VD_DEV_NCC] ([CD_CTR_NCC])
ON UPDATE CASCADE
ON DELETE CASCADE

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] CHECK CONSTRAINT [FK_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_PDV_VD_DEV_NCC]

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC]  WITH CHECK ADD  CONSTRAINT [FK_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_RC_ADM_CARTAO_MOV_LOTE_PDV_VD] FOREIGN KEY([CD_CTR_LOTE], [CD_EMP], [CD_FILIAL], [CD_VD], [CD_CTR])
REFERENCES [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD] ([CD_CTR_LOTE], [CD_EMP], [CD_FILIAL], [CD_VD], [CD_CTR])
ON UPDATE CASCADE
ON DELETE CASCADE

ALTER TABLE [dbo].[RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC] CHECK CONSTRAINT [FK_RC_ADM_CARTAO_MOV_LOTE_PDV_VD_PDV_VD_DEV_NCC_RC_ADM_CARTAO_MOV_LOTE_PDV_VD]
END