SQL语句 增加列、修改列、删除列

1 添加字段

语法 : alter table 表名称 add 字段名称 类型
demo:
  alter table tableName add columnName varchar()

2 更改字段类型(或者字段长度)

语法 :alter table 表名 alter column 字段名 set data type 类型
demo:
  alter table tableName alter column columnNamn set data type varchar()

注意:

  1. 更改字段类型是有操作限制的. 将字段改为比之前类型长度大的可以,如果要改小,必须先drop掉原来的column,然后再重新添加.
  2. 另外改为不同的类型,也需要先drop掉column.然后再重新添加;

3 删除字段

alter table 表名称 drop column 字段名

4 为字段添加默认值

alter table 表名称 alter column 字段名 set default 值

Demo:
alter table table_name altercolumn column_test set default 'value';

5 添加带默认值的字段

Demo:
alter table table_name addcolumn column_test vachar()not null with default 'value';

6 设置字段默认时间为当前时间

Demo:
alter table table_name altercolumn column_test set default current date;

DB2 alter 新增/删除/修改列的更多相关文章

  1. DB2—alter追加/删除/重置column操作

    DB2—alter追加/删除/重置column操作   1.添加字段   alter table 表名称 add 字段名称 类型   Demo: 1 alter table table_name  a ...

  2. Sql增加,删除,修改列

    1. 查看约束条件 - MySQL: SELECT * FROM information_schema.`TABLE_CONSTRAINTS` where table_name = 'book'; - ...

  3. JavaScript学习笔记-商品管理新增/删除/修改功能

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  4. asp.net(C#)html无限分类树 可新增 删除 修改

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductSort.aspx ...

  5. Javascript-商品管理新增/删除/修改功能

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  6. Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法

    一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Orac ...

  7. mysql修改表名,列名,列类型,添加表列,删除表列

    alter table test rename test1; --修改表名 ); --添加表列 alter table test drop column name; --删除表列 ) --修改表列类型 ...

  8. oracle_分区表的新增、修改、删除、合并。普通表转分区表方法

    一. 分区表理论知识Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Oracl ...

  9. mssqlserver修改表名,列名,添加表列,删除表列,修改表列类型

    mssqlserver修改表名,列名,添加表列,删除表列,修改表列类型 ,代码肯定省事的呀 --添加表列 alter table test ) null; --删除表列 alter table tes ...

随机推荐

  1. javascript两个数组内容合并

    需求: ,,]; ,,]; 最终结果: [,,,,,] 代码: Array.prototype.addAll= function(arr) { this.push.apply(this, arr); ...

  2. [C++]Yellow Cards - GYM - 102348A(Practice *) - CodeForces

    1 Problem Description Problem The final match of the Berland Football Cup has been held recently. Th ...

  3. HAProxy+Keepalived 高可用负载均衡

    转自 https://www.jianshu.com/p/95cc6e875456 Keepalived+haproxy实现高可用负载均衡 Master backup vip(虚拟IP) 192.16 ...

  4. RabbitMQ简单Java示例——生产者和消费者

    添加Maven依赖: 使用rabbitmq-client的最新Maven坐标: <!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp ...

  5. linux LVM 系统盘扩容

    1.fdisk /dev/sda2.输入n,开始创建新分区3.输入p4.输入w5.mkfs.ext4 /dev/sda36.pvcreate /dev/sda37.vgdisplay 查看VG nam ...

  6. Re-ranking Person Re-identification with k-reciprocal Encoding

    Re-ranking Person Re-identification with k-reciprocal Encoding Abstract In this paper, we propose a ...

  7. Docker-compose容易忽略的使用细节

    Docker-compose是docker官方的开源项目,通过使用模版yaml文件,实现对docker容器集群的管理.具体教程可以通过官方地址进行实践.Docker-compose主要有两个重要的概念 ...

  8. Had I not seen the Sun(如果我不曾见过太阳)

    Had I not seen the Sun by Emily Dickinson Had I not seen the Sun I could have borne the shade But Li ...

  9. YUV RGB 格式转换

    第一个公式是RGB转YUV(范围0-255)时用的,第二个公式是用在YUV转换RGB(范围0-255)时用的.1. Y = ; U = -; V = ; 黑色:Y=16 ,U= V =128 红色:Y ...

  10. 【转】MySql 三大知识点——索引、锁、事务

    索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. 索引的优点:1. 天生排序.2. 快速查找. 索引的缺点:1. 占用空间.2. 降低更新表的速度. 注意点:小表使用全表扫描更快 ...