sqlserver怎么在建表的时候建立索引idnex
本文介绍了sqlserver怎么在建表的时候建立索引idnex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
1.百度只找到这样的
--创建索引
CREATE NONCLUSTERED INDEX IX_TEST_TNAME --创建一个非聚集索引
ON TEST(TNAME) --为TEST表的TNAME字段创建索引
WITH FILLFACTOR = 30 --填充因子为30%
GO
2.我想要能在见表的时候建索引的语法,没接触过sqlserver,不知道怎么写。
解决方案
你用什么版本的SQL Server,在SQL Server2014前不支持建表的脚本中创建索引,仅支持CONSTRAINT
建完表在创建索引
CREATE TABLE MyTable(
a int NOT NULL
,b smallint NOT NULL
,c smallint NOT NULL
,d smallint NOT NULL
,e smallint NOT NULL
-- This creates a primary key
,CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (a)
,CONSTRAINT IX_MyTable1 UNIQUE (b, c)
);
GO
CREATE NONCLUSTERED INDEX IX_MyTable4 ON MyTable (d, e);
GO
如果是2014,则支持同时创建索引
CREATE TABLE MyTable(
a int NOT NULL
,b smallint NOT NULL
,c smallint NOT NULL
,d smallint NOT NULL
,e smallint NOT NULL
-- This creates a primary key
,CONSTRAINT PK_MyTable PRIMARY KEY CLUSTERED (a)
-- This creates a unique nonclustered index on columns b and c
,CONSTRAINT IX_MyTable1 UNIQUE (b, c)
-- This creates a non-clustered index on (d, e)
,INDEX IX_MyTable4 NONCLUSTERED (d, e)
);
GO
这篇关于sqlserver怎么在建表的时候建立索引idnex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文