SQL ALTER Query:
SQL ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
T0 Add A Column In A Table – Syntax:
ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE SCOREBOARD ADD DotBalls int;
In the above image, you could find total number of columns are 5 (such as Playername, Runs, Balls, Sixers, and fours) related to first SELECT query where as the total number of columns are 6 (such as Playername, Runs, Balls, Sixers, fours, and DotBalls) related to second SELECT query. We have executed ALTER statement to add a new column (DotBalls) in the table ‘SCOREBOARD’.
To Delete A Column In A Table – Syntax:
Note: Some database systems don’t allow deleting a column.
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE SCOREBOARD DROP COLUMN DotBalls;
To Change The Data Type Of A Column In A Table – Syntax:
ALTER TABLE table_name ALTER COLUMN column_name datatype;
Check out the complete SQL Tutorial by clicking on below link: