Drop Foreign Key without knowing the name of the constraint?

后端 未结 7 1154
遇见更好的自我
遇见更好的自我 2020-12-15 03:59

I have created one table using below command:

create table Table1(
    Id int Not Null 
        Foreign key 
        references Table2(Id)  
        on delet         


        
相关标签:
7条回答
  • 2020-12-15 04:47

    Similar to Ed's Answer but you can use this to select the key name based on the table and column name.

    That way you can run it in a script or maybe as a subquery to drop the constraint.

    SELECT CONSTRAINT_NAME
    FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    WHERE TABLE_NAME =  'post'
    AND COLUMN_NAME =  'userID'
    
    0 讨论(0)
提交回复
热议问题