我試着去創建一個名爲「Receita」,其中包含來自一個名爲FarmacoSQL創建一個表
但對於原因,我不斷收到此錯誤並表的外鍵的表我不是真的拿起它
"There is already an object named 'Farmaco' in the database."
繼承人其中i創建兩個表鱈
if not exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[Receita]'))
begin
CREATE TABLE Receita(
IDReceita int NOT NULL
CHECK(IDReceita>0),
IDFarmaco int,
CONSTRAINT PK_IDReceita PRIMARY KEY (IDReceita),
CONSTRAINT FK_IDFarmaco FOREIGN KEY (IDFarmaco)
REFERENCES Farmaco (IDFarmaco)
ON UPDATE CASCADE,
);
end
和
if not exists (select * from dbo.sysobjects
where id=object_id(N'[dbo.Farmaco]'))
begin
CREATE TABLE Farmaco(
IDFarmaco int NOT NULL
CHECK(IDFarmaco>0),
IDMedico int,
Tipo varchar(50)
CONSTRAINT PK_IDFarmaco PRIMARY KEY (IDFarmaco),
CONSTRAINT FK_IDMedico7 FOREIGN KEY (IDMedico)
REFERENCES Médico (IDMedico)
ON UPDATE CASCADE,
);
end
謝謝
對象不需要是表格。 –
問題是:我已經做了5或6個表格,使用相同的代碼(具有不同的名稱的c),它運行良好,當我這樣做時,出現了一個錯誤,我不知道什麼是錯的 –
您可以選擇sysobjects找到'Farmaco'是... – TriV