Retreive a Customized List with input data I have a database that has about 223 tables and I need to locate the name of the constraint.

My request is to add a parameter that is the name of the constraint and you retrieve a list that shows the name of the table and its column. In other word, two column. You show the list that is using the specific constraint based on input data.

I do not know how to create it. I'm a rookie in SQL server

Thanks!
My request is to add a parameter that is the name of the constraint and you retrieve a list that shows the name of the table and its column.


use AdventureWorks2012;

declare @ConstraintName varchar(max)

set @ConstraintName = 'CK_Product_ProductLine' --&lt;--- Change  here with your constraint Name

if exists (
        select 1
        from sys.objects
        where OBJECT_NAME(OBJECT_ID) = '' + @ConstraintName + ''
        )
begin
    select OBJECT_NAME(OBJECT_ID) as NameofConstraint
        ,SCHEMA_NAME(schema_id) as SchemaName
        ,OBJECT_NAME(parent_object_id) as TableName
        ,[type_desc] as ConstraintType
    from sys.objects
    where type_desc like '%CONSTRAINT'
        and OBJECT_NAME(OBJECT_ID) = '' + @ConstraintName + ''
end
else
    select 'There is no constraint with the name that you specified'


Below will be output :