-- How to use SQL to change the data type of columns in a table and add new columns and constraints
-- Add a column
Alter table table name Add column name varchar (20) null
-- Delete a column
Alter table Table Name drop column name
-- Modify a column
Alter table table name alter column name varchar (40) null
-- Modify the type of a column
Alter table table name alter column name varchar (40)
-- Add primary key constraints
Alter table table name
Add constraint name primary key (column name)
-- Add a unique constraint
Alter table table name
Add constraint name unique (column name)
-- Add default Constraints
Alter table table name
Add constraint name default (content) for column name
-- Add check Constraints
Alter table table name
Add constraint name check (content)
-- Add a foreign key constraint
Alter table table name
Add constraint name foreign key (column name) references another table name (column name)
-- Delete Constraints
Alter table table name
Drop constraint name
-- Vertically join two tables
Select * From stuinfo Union
Select * From stumarks
-- Rename, table name
Exec sp_rename 'original table name', 'change table name'
-- Rename, column name
Exec sp_rename 'table name. Original column name', 'changed column name', 'column'