How to Alter Datatype in Sql Server
ALTER TABLE is one of the most useful statement in Sql Server. Its used to add, delete, or modify columns in an existing table. By using alter table statement we can easily alter datatype in Sql Server. Let see the statement with examples.
Example for alter datatype in sql server
USE tempdb
CREATE TABLE dbo.Employee
(EmpID INT, Name VARCHAR(10), LastName DATETIME)
use sp_help 'Employee' to check datatype details
Example for alter datatype INT to varchar
ALTER TABLE dbo.Employee
ALTER COLUMN EmpID VARCHAR(100)
Example for alter datatype varchar to Int
ALTER TABLE dbo.Employee
ALTER COLUMN Name int
Example for alter datatype datetime to varchar
ALTER TABLE dbo.Employee
ALTER COLUMN LastName VARCHAR(100)
0 comments: