Frage

Ich habe ein Skript mit einem DROP TABLE-Befehl wie dem folgenden:

IF EXISTS ( SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('msdb.dbo.lobloblob') AND type in (N'U'))
DROP TABLE msdb.dbo.lobloblob
CREATE TABLE msdb.dbo.lobloblob
....

Dieser Befehl wird ordnungsgemäß ausgeführt. Im Skript wird der Befehl drop jedoch nicht ausgeführt und schlägt diesen Fehler vor

In der Datenbank befindet sich bereits ein Objekt mit dem Namen 'msdb.dbo.lobloblob'

War es hilfreich?

Lösung

Versuchen Sie es

IF OBJECT_ID('msdb.dbo.lobloblob', 'U') IS NOT NULL
    DROP TABLE msdb.dbo.lobloblob;

CREATE TABLE msdb.dbo.lobloblob (...);

stattdessen.Ich gehe davon aus, dass Sie dieses Skript aus dem Kontext einer anderen Datenbank als msdb ausführen, sodass es nicht in sys.objects enthalten ist

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top