- 1、本文档共3页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 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
您可能关注的文档
- 饱和盐水钻井液配制.doc
- 反比例函数小综合.doc
- 清华大学“应用随机过程”习题答案.pdf
- 2013高考数学(文)二轮复习配套作业(解析版):专题限时集训(十一)(新课标).doc
- 重庆科技学院概率论与数理统计期末真题1.doc
- 2005市政真题.doc
- 哈尔滨六中模拟 理综.doc
- matlab6工具箱(补充).ppt
- 30-40岁男人的运动方案.doc
- 调查表 反馈表.doc
- 2025年高二政治毕业会考全套复习知识清单(完整版).pdf
- 2025年高考地理总复习人教版高中地理690个知识点汇总(超全).pdf
- 2025年高考历史总复习必修二经济史全套知识背诵清单(全册完整版).pdf
- 2025年高考历史总复习人民版高中历史必修一知识点精细化整理(精华版).pdf
- 2025年高考历史总复习高中历史岳麓版必修一全册一轮复习考点梳理(精华版) .pdf
- 2025年高考历史总复习人教版高中历史必修一全册复习提纲(精品).pdf
- 2025年高考地理总复习熟记高中全部地理知识点(口诀(附图) 顺口溜).pdf
- 2025年高考历史总复习中国近代史基础知识梳理提纲(精品).pdf
- 2025年高考历史总复习中国近代史专题复习提纲(精华版).pdf
- 2025年高考地理(鲁教版江苏专用)知识复习提纲:选修部分.pdf
文档评论(0)