1. How to add a column
2. How to update a column
3. How to drop a column
Suppose we have a table say Employee whose structure is given below:-
CREATE TABLE Employee (Emplyeeid int identity(1,1),
Empnumber nvarchar(10),
Firstname nvarchar(50),
Lastname nvarchar(150),
Age int,
Phoneno nvarchar(15),
Address nvarchar(200),
Empdate datetime)
Insert query for Inserting data in the table is given below:-
Insert Into employee Values
(‘mani123′,’Manish’, ‘Arora’,27,’245121′,’Delhi’,getdate())
We can see the data in table employee through the following SQL Statement:-
Select * from Employee
Now suppose we want to update the column Firstname of the table Employee by increasing its character limits from 50 to 100. The SQL statement used for this column updation will be:-
Alter table Employee Alter column Firstname nvarchar(100)
Again suppose we want to add a column Regdate into the table Employee then the Sql statement for adding the column into the table Employee will be given below:-
Alter table Employee Add Regdate datetime null
The above SQL statement will add a nullable column Regdate to the table which have the datatype as datetime.
The insert command after the addition of the new column regdatum will be given below:-
Insert Into employee Values
(‘VJO’,’Vivek’, ‘Johari’,28,’244555121′,’Delhi’,getdate(),’01/01/2012′)
Select * from Employee
Suppose if we want to delete a column from the table then we have to write the following SQL Statement
Alter Table Employee Drop Column Regdate
This command will drop the column Regdate from the table Employee which we can verify with the help of the select command.
Select * from Employee
from the above picture, it can be easily see that the column Regdate is not a column of the table Employee anymore.
Discover more from Technology with Vivek Johari
Subscribe to get the latest posts sent to your email.
Today is my first day to read this article, it realy helful……..
example is so simply explain just like any teacher explain vitally……..
thanks sir………..
… [Trackback]
[…] Information to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Information here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Information here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More Information here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More on to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Here you can find 96699 more Info to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Info here to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] There you will find 41135 additional Information on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More Information here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Information here to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Information on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More Info here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Info here to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More here to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] There you will find 85628 more Info to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More Information here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Here you can find 67223 additional Info on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] There you will find 90657 more Information to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Find More to that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More Info here on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]
… [Trackback]
[…] Read More on on that Topic: techmixing.com/2012/04/adding-deleting-and-updating-column-in.html […]