PD11
SQL Server 2000新建索引的时候,打开索引属性,选择columns页,添加上建立索引的列以后
发现上面有个columns definition 选项,里面有none跟主键两个选项
不知道干什么用的.自己测试了一下,发现如果选择主键的话,索引列跟主键列是一样的,但最终生成的sql语句跟不建这个index竟然没有什么差别.这究竟何解呢?
SQL Server 2000新建索引的时候,打开索引属性,选择columns页,添加上建立索引的列以后
发现上面有个columns definition 选项,里面有none跟主键两个选项
不知道干什么用的.自己测试了一下,发现如果选择主键的话,索引列跟主键列是一样的,但最终生成的sql语句跟不建这个index竟然没有什么差别.这究竟何解呢?
我的PD10
没看到你说的东西
=======================================新建一个index => 属性 => columns => 这页没有那个选项吗?
还是model的菜单下面
我的是英文版的
就是在定义index的列的列表的上方阿!,紧挨着快捷图标
如果索引是主健,就相当于见个主健
/*==============================================================*/
/* Table : dept */
/*==============================================================*/
create table dept (
code int not null,
name char(20) not null,
constraint PK_DEPT primary key (code)
)
go
/*==============================================================*/
/* Index: name */
/*==============================================================*/
create unique index name on dept (
code
)
go
不选择:
/*==============================================================*/
/* Table : dept */
/*==============================================================*/
create table dept (
code int not null,
name char(20) not null,
constraint PK_DEPT primary key (code)
)
go
/*==============================================================*/
/* Index: name */
/*==============================================================*/
create unique index name on dept ()
go
有一点点区别.
code
)create unique index name on dept ()
--------
对SQL不怎么了解,谁能解释一下上面的区别.
code
)在code上创建唯一索引
--倒是没看到过
为给定表或视图创建索引。只有表或视图的所有者才能为表创建索引。表或视图的所有者可以随时创建索引,无论表中是否有数据。可以通过指定限定的数据库名称,为另一个数据库中的表或视图创建索引。语法
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
[ WITH < index_option > [ ,...n] ]
[ ON filegroup ]< index_option > ::=
{ PAD_INDEX |
FILLFACTOR = fillfactor |
IGNORE_DUP_KEY |
DROP_EXISTING |
STATISTICS_NORECOMPUTE |
SORT_IN_TEMPDB
}--一定要有一个列阿
怎么会没有
PD生成的就是这代码.
--
我也看到了
并没有见个索引阿
奇怪
/* Table: "Table_75" */
/*==============================================================*/
create table "Table_75" (
"Column_1" CHAR(10),
"Column_2" CHAR(10) not null,
constraint PK_TABLE_75 primary key ("Column_2")
);/*==============================================================*/
/* Index: "Index_1" */
/*==============================================================*/
create index "Index_1" on "Table_75" (
"Column_1" ASC
);你选择none后,应该add一个列
这样才是建立一个索引在列上
如果不选列,后面肯定汇报错误的
第二种:建立索引,且columns definition 选项选择 None
(这种情况肯定要给索引添加列阿)
第三种:建立索引,且columns definition 选项选择 主键其中第一种跟第三种做法 生成的代码是一样的。
我的问题就是既然是一样的,那么这个选项的功能是什么?
因为如果一个index都没有的话就会出现这样的警告
/* Table: "Table_1" */
/*==============================================================*/
create table "Table_1" (
"Column_1" CHAR(10) not null,
"Column_2" CHAR(10),
"Column_3" CHAR(10),
constraint PK_TABLE_1 primary key ("Column_1")
);/*==============================================================*/
/* Index: "Index_1" */
/*==============================================================*/
create unique index "Index_1" on "Table_1" (
"Column_1" ASC
);
/* Table: "Table_1" */
/*==============================================================*/
create table "Table_1" (
"Column_1" CHAR(10) not null,
"Column_2" CHAR(10),
"Column_3" CHAR(10),
constraint PK_TABLE_1 primary key ("Column_1")
);
第三种:建立索引,且columns definition 选项选择 主键
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2000 */
/* Created on: 2006-12-22 10:47:14 */
/*==============================================================*/
if exists (select 1
from sysobjects
where id = object_id('Table_1')
and type = 'U')
drop table Table_1
go/*==============================================================*/
/* Table: Table_1 */
/*==============================================================*/
create table Table_1 (
id int not null,
name varchar(20) null,
constraint PK_TABLE_1 primary key (id)
)
go这个跟不建立索引的情况生成的代码是一抹一样的!!!
/* Table: "Table_1" */
/*==============================================================*/
create table "Table_1" (
"Column_1" CHAR(10) not null,
"Column_2" CHAR(10),
"Column_3" CHAR(10),
constraint PK_TABLE_1 primary key ("Column_1")
); --只有主见
===============================================================
有主见,加了了一个索引
drop index "Index_1";drop table "Table_1" cascade constraints;/*==============================================================*/
/* Table: "Table_1" */
/*==============================================================*/
create table "Table_1" (
"Column_1" CHAR(10) not null,
"Column_2" CHAR(10),
"Column_3" CHAR(10),
constraint PK_TABLE_1 primary key ("Column_1")
);/*==============================================================*/
/* Index: "Index_1" */
/*==============================================================*/
create unique index "Index_1" on "Table_1" (
"Column_1" ASC
);
你上面的是哪种情况?
你上面的是哪种情况?
我上面当然选择的是主见
晕倒!那我的为什么不选择主键就不生成索引了呢!我狂晕!!!
--
好好看看清楚
别像我刚才竟然在看概念模型
第三种:建立索引,且columns definition 选项选择 主键其中第一种跟第三种做法 生成的代码是一样的。
我的问题就是既然是一样的,那么这个选项的功能是什么?----
我这便测试的就是这两个方法的
代码完全不同