I have to create a column in an existing table and at the same time create a foreing key with another table using this column that was created, and this foreing key by default must be null. The way I'm doing is
IF NOT EXISTS (SELECT * FROM SYSCOLUMNS C INNER JOIN SYSOBJECTS T ON C.id = T.id WHERE C.name = ('IdSetorPreparo') AND T.name = 'Produto')
BEGIN
ALTER TABLE Produto
ADD IdSetorPreparo int
END
ALTER TABLE Produto
ADD CONSTRAINT FK_Produto_IdSetorPreparo FOREIGN KEY(IdSetorPreparo) REFERENCES OrgSetor(id)
Well, I wanted to know if it's possible at the same time to create the column already creating the foreing key.