Sequence referenced by table

Find which table references a sequence qith the following statement:

SELECT s.object_id AS sequence_object_id,<br>s.name AS sequence_name,<br>OBJECT_SCHEMA_NAME(o.parent_object_id) + '.'<br>+ OBJECT_NAME(o.parent_object_id) AS table_name,<br>r.*<br>FROM sys.sequences s<br>CROSS APPLY sys.dm_sql_referencing_entities(<br>OBJECT_SCHEMA_NAME(s.object_id) + '.' + s.name,<br>'OBJECT'<br>) r<br>JOIN sys.objects o<br>ON o.object_id = r.referencing_id

Leave a Reply

Your email address will not be published. Required fields are marked *