Tutorials Hut

  • SQL Testing




  • SQL - Alter Table Statement

    SQL ALTER TABLE is used to add, rename, modify or drop columns

    RENAME A TABLE:

    Syntax:

    RENAME TABLE Existing_TableName TableName TO New_TableName

    Example:

    RENAME TABLE Employee TO Student

    TO ADD A COLUMN:

    Syntax:

    ALTER TABLE TableName ADD ColumnName data_type;

    Example:

    ALTER TABLE Employee ADD Address VARCHAR(255);

    Modify a column

    Syntax:

    ALTER TABLE TableName MODIFY ColumnName column_type;

    Example:

    ALTER TABLE Employee MODIFY  EmployeeID int NOT NULL;

    DROP A COLUMN:

    Syntax:

    ALTER TABLE TableName DROP COLUMN ColumnName;

    Example:

    ALTER TABLE Employee  DROP COLUMN Address;

    RENAME A COLUMN:

    Syntax:

    ALTER TABLE TableName  RENAME COLUMN Old_Name to New_Name;

    Example:

    ALTER TABLE Employee  RENAME COLUMN Address to Permanent_ADDRESS;

    Recommended Articles:



  • SQL Testing


















  • Leave a Reply

    Your email address will not be published. Required fields are marked *