📅  最后修改于: 2023-12-03 15:20:14.750000             🧑  作者: Mango
The ALTER TABLE
statement in SQL Server is used to add a new column to an existing table. In this case, we want to add a column with the data type tinyint
.
The syntax for adding a column to an existing table is as follows:
ALTER TABLE table_name
ADD column_name tinyint;
Where:
table_name
is the name of the table to which the column is to be added.column_name
is the name of the new column to be created.tinyint
is the data type for the new column, which in this case represents a small integer between 0 and 255.Keep in mind that the actual values stored in the tinyint
column should be within the range mentioned above.
Here's an example usage of the ALTER TABLE
statement to add a tinyint
column named status
to a table named users
:
ALTER TABLE users
ADD status tinyint;
This will add a new column named status
with the data type tinyint
to the users
table.
By adding a tinyint
column, you can store small integer values efficiently, consuming less storage space compared to an int
or bigint
data type.
Remember to adjust the statement according to your specific table and column names.