The command in SQL used to modify the table structure is ALTER TABLE, which allows you to change columns, constraints, and indexes without losing data. Common ALTER TABLE operations include adding or dropping columns (ADD/DROP COLUMN), modifying column data types (ALTER COLUMN), adding or dropping constraints (ADD/DROP CONSTRAINT), and adding or dropping indexes (ADD/DROP INDEX).

The command used to modify the table structure in SQL
The command used to modify the table structure in SQL isALTER TABLE. It allows you to change columns, constraints, and indexes in a table without losing data.
Use theALTER TABLEcommand
ALTER TABLEThe basic format of the syntax is as follows:
ALTER TABLE table_name ALTER_SPECIFICATION
where ,table_nameis the name of the table to be modified, andALTER_SPECIFICATIONspecifies the changes to be made.
COMMONALTER_SPECIFICATION
Example
The following example will add a new column namedphone_numberto thecustomerstable:
ALTER TABLE customers ADD COLUMN phone_number VARCHAR(20);
shipping_addresscolumn from theorderstable:
ALTER TABLE orders DROP COLUMN shipping_address;
productstable The data type of thepricecolumn isDECIMAL:
ALTER TABLE products ALTER COLUMN price DECIMAL(8, 2);
The above is the detailed content of What command can be used in sql to modify the structure of the table?. For more information, please follow other related articles on the PHP Chinese website!