#What is the SQL statement to add a field?
The standard SQL statement to add a field to the data table is:
alter table 表名 add (字段 字段类型) [ default '输入默认值'] [null/not null] ;
Example:
ALTER TABLE employee ADD spbh varchar(20) NOT NULL Default 0
It means to add the field spbh to the table employee. This field The type is varchar, the size is 20, and is not allowed to be empty. The initial default value is 0.
Extended information:
Other commonly used sql statements:
1. Modify a field attribute in the data table and add comments to it .
Statement format:
comment on column 库名.表名.字段名 is '输入的备注';
Example: I want to add comments to the document_type field of the test table in the ers_data library, then the sql statement is:
comment on column ers_data.test.document_type is '文件类型';
2. Modify a certain field in the data table Field Type.
Statement format:
alter table 表名 modiy (字段 字段类型 [default '输入默认值' ] [null/not null] ,字段 字段类型 [default '输入默认值' ] [null/not null] );
Modify multiple fields separated by commas.
Example: If you want to modify the type of field office classroom in a teacher table to char (20), and the default value is "office", the corresponding sql is:
ALTER TABLE teacher ALTER COLUMN classroom VARCHAR(20) NOT NULL default "办公室";
3. Delete data A field in the table.
Statement format:
alter table 表名 drop (字段);
Example: To delete the field age in the table student, you can use the following sql:
alter table student drop age;
Recommended tutorial: "sql tutorial 》
The above is the detailed content of What is the statement to add fields in sql. For more information, please follow other related articles on the PHP Chinese website!