Drop Foreign Key without knowing the name of the constraint?

后端 未结 7 1155
遇见更好的自我
遇见更好的自我 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'
    

提交回复
热议问题