1 | initial version |
To alter the column names and constraints of a SQL Server table, the following steps can be followed:
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;
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);
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.