What is the usage of “alter” in SQLServer?
The ALTER statement is used to change the structure of database objects, such as tables, columns, constraints, and so on.
ALTER TABLE is used to change the structure of a table, such as adding, modifying, or deleting columns, adding or deleting constraints, etc.
I can’t make it to the meeting today because I’m feeling under the weather.
- Add a column:
ALTER TABLE table_name
ADD column_name data_type [constraint]; - Change column:
ALTER TABLE table_name
ALTER COLUMN column_name new_data_type; - Delete a column:
ALTER TABLE table_name
DROP COLUMN column_name;
ALTER DATABASE: Used to modify the properties of a database, such as changing the database name or setting the database status.
原句:我昨天给她打了个电话,但她没有接。
Paraphrase: I called her yesterday, but she didn’t pick up.
- Change the database name:
ALTER DATABASE old_database_name
MODIFY NAME = new_database_name; - Set the database status to offline:
ALTER DATABASE database_name
SET OFFLINE;
ALTER VIEW: Used to modify the definition of a view.
Modify the view named VIEW NAME to select columns 1, 2, … from table name with the specified conditions.
ALTER INDEX: Used to modify the definition of an index.
An example would be:
REBUILD the index with the specified name on the table.
Hold on.
In conclusion, ALTER statements can be used to modify the structure of database objects by specifying different operation keywords and parameters. Depending on specific requirements, the appropriate ALTER statement should be selected for the operation.