Alter Table Primary key - Crate DB

前端 未结 2 1829
慢半拍i
慢半拍i 2021-01-27 10:40

I want to alter a table in my Crate DB to change the primary key constraint to add a column to the existing one. If I need to drop the constraint and create a n

2条回答
  •  日久生厌
    2021-01-27 11:43

    First use the following code snippets for finding the constraints

    SELECT Col.Column_Name from 
        INFORMATION_SCHEMA.TABLE_CONSTRAINTS Tab, 
        INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE Col WHERE 
           Col.Constraint_Name = Tab.Constraint_Name
           AND Col.Table_Name = Tab.Table_Name
           AND Constraint_Type = 'PRIMARY KEY'
           AND Col.Table_Name = ''
    

    Then use this to drop the constraint

    ALTER TABLE Customer DROP CONSTRAINT Constraint_Name;
    

    P.S: considering you are using SQL SERVER

提交回复
热议问题