
/*------ ATD 386986 ------*/
IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='PreVenda') 
BEGIN
CREATE TABLE PreVenda(
Id int identity NOT NULL,
Descricao varchar(100) NOT NULL,
CodigoVendedor varchar(5) NULL,
DataCriacao datetime NOT NULL,
NumPed int NULL)
ALTER TABLE PreVenda ADD CONSTRAINT PK_PreVenda PRIMARY KEY CLUSTERED(Id)
END
GO


IF NOT EXISTS (SELECT 1 FROM SYSOBJECTS WHERE xtype='U' AND name='ItemPreVenda') 
BEGIN
CREATE TABLE ItemPreVenda(
Id int identity NOT NULL,
IdPreVenda int NOT NULL,
CodigoProduto varchar(5) NOT NULL,
Quantidade numeric(13, 3) NOT NULL)
ALTER TABLE ItemPreVenda ADD CONSTRAINT PK_ItemPreVenda PRIMARY KEY CLUSTERED (Id)
ALTER TABLE ItemPreVenda WITH CHECK ADD CONSTRAINT [FK_ItemPreVenda_IdPreVenda_PreVenda_Id] FOREIGN KEY([IdPreVenda]) REFERENCES [PreVenda] ([Id])
ALTER TABLE ItemPreVenda CHECK CONSTRAINT [FK_ItemPreVenda_IdPreVenda_PreVenda_Id]
END
GO