【发布时间】:2015-01-07 14:28:27
【问题描述】:
我正在阅读有关如何在 linux 环境中使用 DB2 的教程。
我要连接数据库,创建表,在db2 shell下插入一些数据:
db2 连接到 c3421m
db2
db2 => 使用 z ON Assignment_0.txt 更新命令选项
db2 => 使用 v ON 更新命令选项
db2 => CREATE TABLE BAND_2015 // 给出错误我卡在这里
// 这是我卡住的地方,我应该创建一个表并在 DB2 shell 下执行以下命令:CREATE TABLE BAND_2015
给出的代码:
create table band_2015 ( \
band_no integer not null primary key, \
band_name varchar(25) not null, \
band_home varchar(25) not null, \
band_type varchar(10) check (band_type in (‘concert’,’rock’,’jazz’,’military’)), \
b_start_date date not null, \
band_contact varchar(10) not null )
那么如何创建这个表呢?我被告知将其复制到文本编辑器(我是否将其保存为 band_2015.sql ?)。我对此完全陌生,但我在其他编程语言方面有很多经验......
【问题讨论】:
-
如果你只尝试一个单行命令会发生什么,比如“create table t1 (c1 integer not null primary key)”?
-
db2 => create table t1 给出此错误 -> “DB21034E 该命令被作为 SQL 语句处理,因为它不是有效的命令行处理器命令。在 SQL 处理期间它返回:SQL0104N 意外标记在“create”之后找到“table”。预期的标记可能包括:“TABLESPACE”。SQLSTATE=42601”
-
您不必启动 clp 并从其内部进行操作。另一种方法是直接从 sh 执行 sql 命令。 IE。
db2 "create table band_2015 ( \ band_no integer not null primary key, \ band_name varchar(25) not null, \ band_home varchar(25) not null, \ band_type varchar(10) check (band_type in ('concert','rock','jazz','military')), \ b_start_date date not null, \ band_contact varchar(10) not null )"你也可以把你的sql语句放在一个文件中,并以db2 -tf myfile.sql运行它们