This SQL Server tutorial explains how to use the ALTER TABLE statement in SQL Server (Transact-SQL) to add a column, modify a column, drop a column, rename a column or rename a table with examples.
Sample Table
| Create Table customer( |
| CustomerId int not null Identity(1,1), |
| CustomerName varchar(100), |
| Primary Key(CustomerId) |
| ) |
| |
| Create Table CustomerDetails( |
| DetailsId int not null identity(1,1), |
| CustomerId int foreign key references Customer(CustomerId), |
| sort int, |
| refCode int |
| ) |
Alter table add a column
| Alter Table Customer |
| Add CustomerAddress Varchar(255); |
Alter table add multiple columns
| Alter Table Customer |
| Add |
| ZipCode varchar(50), |
| Country varchar(255), |
| Firstname varchar(255), |
| Lastname varchar(100); |
| |
Amend Column
| Alter Table Customer |
| Alter Column CustomerName varchar(200) not null; |
Drop Column
| Alter Table Customer |
| Drop Column Country |
Please donate and support at
https://www.paypal.me/Rajcoomar
Comments
Post a Comment