Home > Database > SQL > body text

What is the statement to add fields in sql

hzc
Release: 2020-06-17 16:43:38
Original
28992 people have browsed it

What is the statement to add fields in sql

#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]  ;
Copy after login

Example:

ALTER TABLE employee  ADD  spbh varchar(20) NOT NULL Default 0
Copy after login

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.

What is the statement to add fields in sql

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  '输入的备注';
Copy after login

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 '文件类型';
Copy after login

2. Modify a certain field in the data table Field Type.

Statement format:

alter table 表名  modiy (字段  字段类型  [default '输入默认值' ] [null/not null]  ,字段  字段类型  [default '输入默认值' ] [null/not null] );
Copy after login

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 "办公室";
Copy after login

3. Delete data A field in the table.

Statement format:

alter table  表名  drop (字段);
Copy after login

Example: To delete the field age in the table student, you can use the following sql:

alter table student drop age;
Copy after login

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!

Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!