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 the ALTER TABLE
command
ALTER TABLE
The basic format of the syntax is as follows:
<code>ALTER TABLE table_name ALTER_SPECIFICATION</code>
where , table_name
is the name of the table to be modified, and ALTER_SPECIFICATION
specifies the changes to be made.
COMMONALTER_SPECIFICATION
Example
The following example will add a new column namedphone_number to the
customers table:
<code class="sql">ALTER TABLE customers ADD COLUMN phone_number VARCHAR(20);</code>The following example will delete the
shipping_address column from the
orders table:
<code class="sql">ALTER TABLE orders DROP COLUMN shipping_address;</code>The following example will change the
products table The data type of the
price column is
DECIMAL:
<code class="sql">ALTER TABLE products ALTER COLUMN price DECIMAL(8, 2);</code>
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!