Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To alter the column names and constraints of a SQL Server table, the following steps can be followed:

  1. To alter the column name:

    ALTER TABLE tablename RENAME COLUMN oldcolumnname TO newcolumn_name;

    For example:

    ALTER TABLE customers RENAME COLUMN custname TO customer_name;

  2. To add a constraint:

    ALTER TABLE tablename ADD CONSTRAINT constraintname constrainttype (columnname);

    For example:

    ALTER TABLE orders ADD CONSTRAINT fkcustomerid FOREIGN KEY (customerid) REFERENCES customers (customer_id);

  3. To drop a constraint:

    ALTER TABLE tablename DROP CONSTRAINT constraintname;

    For example:

    ALTER TABLE orders DROP CONSTRAINT fk_customerid;

Note: Make sure to replace "tablename", "oldcolumnname", "newcolumnname", "constraintname", "constrainttype" and "columnname" with the actual names of the table, column, and constraint.