Domanda

L'esecuzione della seguente query risulta in tutti i vincoli nel database del nostro client.Tuttavia, diverse righe nel set di risultati non sembrano avere un genitore, I.e. parent_object_id = 0 e OBJECT_NAME(parent_object_id) restituisce NULL.

SELECT name, type_desc, OBJECT_NAME(parent_object_id), parent_object_id
FROM sys.objects
WHERE is_ms_shipped = 0
AND type_desc LIKE '%_CONSTRAINT'
.

Questo significa che ci sono vincoli orfani nel database?Se è così, come faccio a rimuoverle?

Dai loro nomi, posso vedere di essere gli avanzi da prima che venissero apportate modifiche di grandi dimensioni alla struttura.

È stato utile?

Soluzione

Using sp_helptext I can see they were created using a CREATE DEFAULT statement, e.g.:

CREATE DEFAULT dbo.MyDefault AS 2

This means they are simply unbound defaults, which can be bound using the sp_binddefault according to MSDN, and removed with a simple DROP DEFAULT statement:

DROP DEFAULT dbo.MyDefault

I wasn't aware of this syntax, which apparently will be removed in a future version of SQL Server, according to the aforementioned MSDN article.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top