Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change the datatype of a column in SQL Server

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 329
    Comment on it

    Hello Reader!If you wish to add, delete or modify columns in an existing table you can do this with the help of ALTER command.

    The syntax to change or we can say to modify a column in an existing table in SQL server is:

    ALTER TABLE table-name
    ALTER COLUMN column_name column_type;

    Example:

      ALTER TABLE employees
      ALTER COLUMN first_name VARCHAR(40) NOT NULL;

    Following example will modify the column first_name to be a datatype of VARCHAR(40) and will force a column to not allow null values.

    The syntax to add new column in an existing table in SQL server is:

    ALTER TABLE table-name
     ADD column_name datatype;

    Example:

    ALTER TABLE employees
     ADD department  varchar(15);

    Following example will add the column department to an existing table employee of datatype VARCHAR with size upto 15 characters.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: