Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Especifica el nombre de la tabla y el atributo que estás buscando
- DECLARE @NombreTabla NVARCHAR(128) = '';
- DECLARE @NombreAtributo NVARCHAR(128) = '';
- -- Consulta para obtener las claves foráneas que hacen referencia al atributo en la tabla
- SELECT
- OBJECT_NAME(f.parent_object_id) AS TablaReferente,
- COL_NAME(fc.parent_object_id, fc.parent_column_id) AS AtributoReferente,
- OBJECT_NAME(f.referenced_object_id) AS TablaReferenciada,
- COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS AtributoReferenciado,
- f.name AS NombreConstraint
- FROM
- sys.foreign_keys AS f
- INNER JOIN
- sys.foreign_key_columns AS fc ON f.object_id = fc.constraint_object_id
- WHERE
- OBJECT_NAME(f.referenced_object_id) = @NombreTabla
- AND COL_NAME(fc.referenced_object_id, fc.referenced_column_id) = @NombreAtributo;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement