IQ使用基础.doc

  1. 1、本文档共3页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
IQ使用基础

IQ使用基础_创建和修改表? 在“IQ 基础入门”这个博文分类中介绍了如何构建一个学习用demo数据库,在随后的文章中将向IQ的初学者介绍一些基本使用知识,这些知识适合于新接触IQ的开发人员和数据库管理人员。 ? 1. 创建表 ? --使用create table语句 create table test_service ( ??? service_key????????? int???? ?not null, ??? call_waiting_flag??? char(1) ?null??? , ??? caller_id_flag?????? char(1) ?null??? , ??? voice_mail_flag????? char(1) ?null??? , ??? cellular_flag??????? char(1) ?null??? , ??? internet_flag??????? char(1) ?null??? , ??? primary key (service_key) ) 注意:IQ建表语法与很多关系型数据库(例如:Sybase ASE)的语法基本相同。如果字段的空值属性没有指定的话,缺省是NULL。 ? --使用select into建表(不包含数据) select * into test_service from service where 1=2 注意:这种方法建立的表不会自动建立索引。 ? ? 2.修改表定义 (1)增加新字段 ???? alter table test_service add isdn_flag char(1) ?null ?注意:增加的字段必须是允许NULL的。 ? (2)删除字段 ???? alter table test_service drop cellular_flag ? (3)字段改名 ???? alter table test_service rename call_waiting_flag to wait_flag (4)增加主键约束 ???? alter table test_service add primary key(service_key) ???? 注意:主键字段一定是NOT NULL的 ? (5)删除主键约束 ???? alter table test_service drop primary key ? (6)修改表名 ???? alter table service rename service1 ? ?(7) 修改字段数据类型 ???? IQ不支持直接修改表中某个字段的数据类型。如果想这样做,可以采用间接方法: ???? a.增加一个新字段(这个字段的类型是你期望的数据类型) ???? b.使用update语句把源字段的值写入新字段(可能需要使用类型转换函数) ???? c.把源字段删除 ???? d.把新增加的字段改为与被删除那个字段的名相同 ? ???? 下面是一个例子,把test1表的age字段类型从int改为tinyint : ???? ???? --准备表和数据 ???? create table test1(id int,name char(8),age int) ???? insert into test1 values(1,aaaa,20) ???? insert into test1 values(2,bbbb,30) ???? commit ? ???? --a.增加一个新字段 ???? alter table test1 add age1 tinyint null ? ???? --b.使用update语句把源字段的值写入新字段 ???? update test1 set age1 = age ? ???? --c.把源字段删除 ???? alter table test1 drop age ? ???? --d.把新增加的字段改为与被删除那个字段的名相同 ?????alter table test1 rename age1 to age ? ???? 还有另一种方法,步骤如下: ???? --a. 使用select into把表数据进行备份 ???? select * into test1_tmp from test1; ? ???? --b. 删除表 ???? drop table test1 ???? ???? --c. 用正确的类型重新创建表 ???? create table test1(id int,name char(8),age tinyint) ? ???? --d. 把数据导回表 ???? insert test select * from test1_tmp

文档评论(0)

qwd513620855 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档