您的位置 首页 技术

sql增加字段的语句是什么

sql增加字段的语句是什么? 数据表中添加一个字段的标准SQL语句写法为: alter table 表名 add (字段 字段类型) [ default '输入默认值&#…

sql增加字段的语句是什么?

数据表中添加一个字段的标准SQL语句写法为:

alter table  表名  add (字段 字段类型)  [ default  '输入默认值']  [null/not null]  ;

举例:

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

意思就是在表employee 中加入 字段spbh,该字段的类型是varchar,大小20,并且不允许为空,初始默认值是0。

decf5f5c2c39fb885582c01ebdb6323.png

扩展资料:

其他常用sql语句:

1、修改数据表中某项字段属性,为其添加备注。

语句格式:

comment on column  库名.表名.字段名 is  '输入的备注';

示例: 我要在ers_data库中 test表 document_type字段添加备注,则sql语句为:

comment on column ers_data.test.document_type is '文件类型';

2、修改数据表中某字段类型。

语句格式:

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

修改多个字段用逗号隔开。

示例:想要修改一个teacher教师表中字段办公室classroom的类型为char(20),且默认值“办公室”,则对应sql为:

ALTER TABLE teacher ALTER COLUMN classroom VARCHAR(20) NOT NULL default "办公室";

3、删除数据表中的某字段。

语句格式:

alter table  表名  drop (字段);

示例:删除表student中的字段age,可以用如下sql:

alter table student drop age;

推荐教程: 《sql教程》

以上就是sql增加字段的语句是什么的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/81554.html

为您推荐

返回顶部