Reason - Sometimes it happens that we
create a schema of any table in the SQL SERVER database. But after a few transactions we start facing problems related to the size of datat type of any field (for e.g. First name
previously declared with 10 characters but some first name is of around 15
characters). The below mentioned code explains the method of doing this with minimum possibility of data
loss.
CREATE
TABLE Employee
(
EmpID INT IDENTITY
(1,1)
NOT NULL,
FirstName VARCHAR(10)
NULL,
MiddleName VARCHAR(10)
NULL,
LastName VARCHAR(10)
NULL
)
-- Change the datatype of FirstName column to support 50
characters and make NOT NULL
ALTER TABLE dbo.Employee
ALTER COLUMN FirstName
VARCHAR(50)
NOT NULL