IQ创建表、视图、索引

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

IQ UNIQUE 关键字定义了字段的聚合度
用于优化 FP 索引的创建 <256 values - Single-byte lookup table (1-byte FP index) >255 and <65537 - Two-byte lookup table (2-byte FP index) Default value is 65,537
6-2
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Module Map
IQ存在三种类型的表 存在三种类型的表: 存在三种类型的表
Base Tables(普通表) (普通表) Local Temporary Tables(局部临时表) Global Temporary Tables(全局临时表)
Creating Views Creating Indexes
6-3
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
ASIQ数据库中表存放示意图 数据库中表存放示意图
6-4
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Administering Adaptive Server IQ for the Data Warehouse
Creating Tables,Views and Indexes
Module Overview
This module describes how to create ASIQ tables and indexes using the correct syntax. It also covers how to create ASIQ views using the correct syntax. Objectives After completing this module, you should be able to:
PRIMARY KEY 关键字会创建HG 索引于字段或复合字 段
但在创建HG索引时不创建G-Array结构
可以使用复合主键
A single unique HG index will be created on the entire key
优化器在做查询时使用PRIMARY KEY约束 约束 DBA must still create individual indexes on the key components for queries
PRIMARY KEY
类似 UNIQUE 关键字的作用,但要注意一张表中只能有一 个PRIMARY KEY
6-6
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE—使用 UNIQUE 使用IQ 使用
CREATE TABLE customer (customer_id int NOT NULL, cust_type char(4) IQ UNIQUE (30), ... postalcode char(9) NULL)
Create, drop, and alter tables Create/drop indexes Create views Make scripts
6-1
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Steps for Deploying an ASIQ Installation
对字段约束是PRIMARY KEY或者 UNIQUE 时自动创建 HG索引
此HG 索引不包含普通HG索引的G-Array结构 必须通过alter table and drop constraint 来删除此HG 索引
6 - 14
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Properly plan and size the database Create ASIQ database(s) Choose ASIQ datatypes and index types for each column 创建ASIQ tables 创建 Create ASIQ indexes
6 ຫໍສະໝຸດ Baidu 17
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Sybase Central建表步骤 Steps 1–3 建表步骤: 建表步骤
1. 连接数据库
Select Tools->Connect->Adaptive Server IQ 输入 user ID, password, port number or ODBC/JDBC
2. Click the Tables folder 3. Double-click Add Table
CREATE TABLE语法 语法
Simple Example Translate entities and attributes to tables and columns 定义字段特性
字段名 字段类型 字段属性
Example:
CREATE TABLE employee (emp_id int NOT NULL ,lname varchar(30) NULL ,fname varchar(30) NULL ,salary money NULL)
6 - 10
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE…约束应用 约束应用
FOREIGN KEY约束 约束 Specifies which column(s) in the created table compare with the columns in the referenced list 此约束 ASIQ在建表时不会做强制检查
6-9
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE—使用 使用PRIMARY KEY 使用
CREATE TABLE product (product_code CHAR(5) NOT NULL ,product VARCHAR(25) NOT NULL ,price MONEY NULL ,primary key (product_code))
6 - 12
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE语法 语法
一个较复杂的建表语法示例: 一个较复杂的建表语法示例:
CREATE TABLE books (isbn char(20) PRIMARY KEY IQ UNIQUE ,copyright_date date NOT NULL ,title char(100) ,author char(50) ,price money NULL)
使用Sybase Central创建表 使用 创建表
1. 连接数据库 2. 点击 Tables folder 3. 双击 Add Table 4. 输入表名 5. 输入字段名, 数据类型, 和其它属性 6. 点击Save
6 - 15
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
UNIQUE 关键字在对应的字段或者复合字段创建唯 一的HG索引
此HG 索引不带G-Array 结构
可以应用于单一或复合字段 优化器(optimizer)在查询时会使用 UNIQUE约束 约束
(continued…)
6-8
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
一个UNIQUE HG 索引将会创建 UNIQUE
此索引在 load, insert or update时会进行唯一性检查
当唯一性检查失败,则事务会回滚 DBA must still create individual indexes on the key components for queries
6-5
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE…中常用关键字 中常用关键字
字段约束关键字 IQ UNIQUE
指出字段的级数 使用此关键字能帮助提高性能
UNIQUE
要求此字段在表中唯一 缺省会创建对应的HG索引 可以是复合字段
CREATE TABLE—使用 使用UNIQUE (复合 复合) 使用 复合
CREATE TABLE order (order_num unsigned int NOT NULL ,order_date date NOT NULL ,customer_id unsigned int NOT NULL ... unique (order_num, order_date, customer_id ))
6 - 16
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
Sybase Central建表步骤 Steps 4–6 建表步骤: 建表步骤
4. 输入表名 5. 输入字段名, 数据类型, 以及其它属性 cntrl-n 快捷键创建下一字段 6. 字段创建完毕, 点击 Save 图标
可以和其它约束一起使用 IQ UNIQUE 约束
(continued…)
6 - 13
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE总结 总结
自动创建索引 ASIQ 对每个字段自动创建FP 索引
假如通过IQ UNIQUE指定了聚合度,当聚合度 < = 255, 指定了聚合度, 指定了聚合度 loading will be optimized to a 1-byte FP 假如通过IQ UNIQUE指定了聚合度,当聚合度 <= 指定了聚合度, 指定了聚合度 65,536, loading will be optimized to a 2-byte FP 假如通过IQ UNIQUE指定了聚合度,当聚合度>=65536 IQ UNIQUE指定了聚合度 当聚合度>=65536 指定了聚合度, (或者不使用IQ UNIQUE), 创建普通的Flat FP index
使用此关键字提高装载性能
减少磁盘占用空间 为优化器( Optimizer)提供帮助
(continued…)
6-7
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE—使用 使用UNIQUE 使用
CREATE TABLE stores (store_id char(4) NOT NULL ,store_name varchar(20) NOT NULL ,store_address varchar(40) NOT NULL ,unique (store_id ))
6 - 11
2002 Sybase, Inc. and its subsidiaries. All rights reserved.
CREATE TABLE语法 语法
在数据库中建表的语法:
CREATE [ GLOBAL TEMPORARY ] TABLE [ owner.]table-name ... ( column-definition [ column-constraint]... [, column-definition [column-constraint] ...]) [, table-constraint ] ...)
相关文档
最新文档