How to add a field and assign a value in SQL?

To add a new column and assign a value, you can use the ALTER TABLE statement. Here is an example:

ALTER TABLE 表名
ADD 列名 数据类型 DEFAULT 默认值;

The table name refers to the name of the table where the field is to be added, the column name is the name of the field to be added, the data type is the type of data for the field, and the default value is the default value for the field.

For example, if there is a table named “users” and we want to add a field named “age” with a value of 30 and a default value of 0, we can use the following statement:

ALTER TABLE users
ADD age INT DEFAULT 0;

This will add an INTEGER type field named “age” to the “users” table, with its default value set to 0.

bannerAds