db2 => select name,salary+comm from staff fetch first 3 rows only
NAME 2
--------- ----------
Sanders -
Pernal 78783.70
Marenghi -
3 record(s) selected.
db2 => insert into tt values(1),(1)
DB20000I The SQL command completed successfully.
db2 => create table pers like staff
DB20000I The SQL command completed successfully.
db2 => update staff set (dept,salary)=(51,70000) where id=150
DB20000I The SQL command completed successfully.
Oraclehedb2都支持下列写法
update tttt set id=3,name='c' where id=1;
db2 => select salary from old table(update staff set salary=salary*0.2 where id=10)
SALARY
---------
19671.50
1 record(s) selected.
db2 => select salary from old table(update staff set salary=salary*0.2 where id=10)
SALARY
---------
3934.30
1 record(s) selected.
会话1
$ db2 +c
db2 => connect to sample
Database Connection Information
Database server = DB2/LINUX 9.7.5
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
db2 => create table czm_1(id int)
DB20000I The SQL command completed successfully.
db2 => insert into czm_1 values(1)
DB20000I The SQL command completed successfully.
db2 => savepoint savepoint1 on rollback retain cursors
DB20000I The SQL command completed successfully.
db2 => insert into czm_1 values(2)
DB20000I The SQL command completed successfully.
db2 => savepoint savepoint2 on rollback retain cursors
DB20000I The SQL command completed successfully.
db2 => select * from czm_1
ID
-----------
1
2
2 record(s) selected.
会话2,执行下面语句无法查询czm_1,hang住不能继续执行
db2 => connect to sample
Database Connection Information
Database server = DB2/LINUX 9.7.5
SQL authorization ID = DB2INST1
Local database alias = SAMPLE
db2 => select * From czm_1
会话1
db2 => rollback to savepoint savepoint1
DB20000I The SQL command completed successfully.
db2 => select * from czm_1
ID
-----------
1
1 record(s) selected.
db2 => rollback
DB20000I The SQL command completed successfully.
db2 => select * from czm_1
SQL0204N "DB2INST1.CZM_1" is an undefined name. SQLSTATE=42704
可以看到会话1在执行完rollback语句后,找不到czm_1这个对象了,
会话2 hang住的select语句也执行完毕
db2 => select * from czm_1
SQL0204N "DB2INST1.CZM_1" is an undefined name. SQLSTATE=42704
db2 -td@ -vf createSQLproc.db2
db2 命令指定 -td 选项标志,这让命令行处理程序使用 @ 作为语句终止字符(因为在过程体内已经使用分号作为语句终止字符);-v 选项标志让命令行处理程序将命令文本回显到标准输出;-f 选项标志让命令行处理程序从指定的文件(而不是标准输入)读取命令输入。
db2 => create table books(bookid integer,bookname varchar(100),isbn char(10)) in userspace1
db2 => alter table books alter bookname set data type char(150) alter isbn set not sqlserver
iis7站长之家
DB20000I The SQL command completed successfully.
修改表列的限制:
在修改字符串列的长度时,只能增加长度。
在修改列的数据类型时,新的数据类型必须与现有的数据类型兼容。例如,可以将 CHAR 列转换为 VARCHAR 列,但是不能将它们转换为 GRAPHIC 或数字列。数字列可以转换为任何其他数字数据类型,只要新数据类型的长度足以容纳其中的值。例如,可以将 INTEGER 列转换为 BIGINT,但是 DECIMAL(10,2) 列不能转换为 SMALLINT。
固定长度的字符串可以转换为可变长度的字符串,可变长度的字符串也可以转换为固定长度的字符串。例如,CHAR(100) 可以转换为 VARCHAR(150)。对于可变长度的图形字符串也有类似的限制。
表的某些特征不可以更改。例如,不可以修改某些列的数据类型、表驻留的表空间或列的次序。要更改这样的特征,必须保存表数据,删除表,然后重新创建表。