To modify the table design of a database, you can use the SQL ALTER TABLE statement, which is used to add, delete, or modify table columns in an existing table.
1> add a new column to the database table:
Grammar:
ALTER table name ADD column name data type
For example: Add a new column birthday in the persons table below, with a data type of varchar (50)
Enter the following syntax in the new query:
ALTER TABLE ADD varchar (+)
The results after insertion are as follows:
2> to delete columns from a table in a database table:
Grammar:
ALTER table table name DROP column name
For example:
Delete the table design of the Birthday column in the persons table, and this column of data is also deleted.
ALTER TABLE DROP Birthday
3> Changing the database table data type:
This statement is used to change the data type of a column of data in a database when the database is designed.
Grammar:
Alter TAVLE table name ALTER COLUMN name new data type
For example:
In the previous persons table, the birthday data type is varchar (50), but now to change the data type to the text type, the statement is as follows:
ALTER TABLE ALTER text
SQL Server Database Tutorial Three, add, delete, modify, table column