Finding which table a constraint belongs to
This will not find indexes which are in sys.indexes
SELECT
OBJECT_NAME(o.parent_object_id)
FROM
sys.objects o
WHERE
o.name = 'MyConstraintName' AND o.parent_object_id <> 0
many things could be considered to be a constraint:
primary key
foreign key
unique index
check constraint
column default
your question is a little vague. Do you know the name of the constraint, the type, etc.?
Based on the limited info in your question. I suggest that you look at the source code to the master.sys.sp_helpconstraint stored procedure.
In Sql Server Management Studio, using the Object Explorer, ust navigate to: "Databases" - "System Databases" - "master" - "Programmability" - "Stored Procedures" - "System Stored Procedures" - "sys.sp_helpconstraint". It contains all the tsql to query all the various kinds of constraints.
gbn, your solution dosn't seam to work?
SELECT
OBJECT_NAME(o.parent_object_id)
FROM
sys.objects o
WHERE
o.name = 'MyConstraintName' AND o.parent_object_id <> 0
So if 'MyConstraintName' becomes 'FK_myConstraint' then the query becomes
SELECT OBJECT_NAME(o.parent_object_id)
FROM sys.objects o
WHERE o.name = 'MyConstraintName'
AND o.parent_object_id <> 0
Which produces no results
(No column name)
It seams that your 'solution' must be based on a whole lot of unstated assumptions about the schema.