Restricciones de huérfanas en la base de datos de SQL Server
-
15-11-2019 - |
Pregunta
Ejecutar los siguientes resultados de consulta en todas las restricciones en la base de datos de nuestro cliente.Sin embargo, varias filas en el conjunto de resultados no parecen tener un padre, es decir, parent_object_id = 0
y OBJECT_NAME(parent_object_id)
devuelve 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'
¿Esto significa que hay restricciones huérfanas en la base de datos?Si es así, ¿cómo elimino estos?
De sus nombres, puedo ver que son sobrantes antes de que se hicieron cambios de gran cantidad a la estructura.
Solución
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.