IF OBJECT_ID('EST_PROD_CPL_ROBO') IS NULL
BEGIN

	CREATE TABLE [dbo].[EST_PROD_CPL_ROBO](
		[CD_EST_PROD_CPL_ROBO] [int] NOT NULL IDENTITY,
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_PROD] [int] NOT NULL,
		[QTDE_PROD] [MONEY] NOT NULL,
		[DT_MOV] [datetime] NOT NULL,
		[CD_USU] [int] NOT NULL,
		[CD_TIPO] [int] NOT NULL,
		[NR_ECF_UUID] [varchar](256) NULL,
		[ORIG_LANC] INT NOT NULL CONSTRAINT DF_EST_PROD_CPL_ROBO_ORIG_LANC DEFAULT 0,
		[OBS] VARCHAR(8000),
		
		CONSTRAINT [EST_PROD_CPL_ROBO_PK] PRIMARY KEY CLUSTERED
		(
		[CD_EST_PROD_CPL_ROBO] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]
END

GO

IF NOT EXISTS (SELECT * FROM SYS.foreign_keys WHERE NAME = 'FK_EST_PROD_CPL_ROBO_EST_PROD_CPL')
BEGIN
	ALTER TABLE EST_PROD_CPL_ROBO ADD CONSTRAINT FK_EST_PROD_CPL_ROBO_EST_PROD_CPL FOREIGN KEY (CD_EMP, CD_FILIAL, CD_PROD) REFERENCES EST_PROD_CPL (CD_EMP, CD_FILIAL, CD_PROD)
END

GO