[英]Equivalent of Index options (using index) in Oracle to SQL Server 2014
I need to move the data from Oracle database to MS SQL Server 2014. But I got the problem with this "USING INDEX" statement which help me in oracle to add some constraint. 我需要将数据从Oracle数据库移动到MS SQL Server2014。但是我遇到了此“使用索引”语句的问题,该语句帮助我在oracle中添加了一些约束。 I would like to know if someone could provide me and equivalence of "USING INDEX" in Sql Server. 我想知道是否有人可以在Sql Server中为我提供“ USING INDEX”的等效功能。
CONSTRAINT "MESSAGE_LOG_RECORD_PK" PRIMARY KEY ("RECORD_NO")
**USING INDEX** PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "DATA" ENABLE,
It seems using index creates index in specified table space as per the parameters you specified. 似乎使用索引根据您指定的参数在指定的表空间中创建索引。 . 。
so you can do below while creating the table,so that sql server will configure index as per default parameters 因此,您可以在创建表时执行以下操作,以便sql server根据默认参数配置索引
create table t1
(
id int not null primary key
)
or else you can use below syntax to add constraint to table once table is created 否则,一旦创建表,您就可以使用以下语法向表添加约束
CREATE CLUSTERED INDEX [indxname] ON [dbo].[table1]
(
id
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
if you leave filegroup option,it will create the index in same filegroup as table is created 如果保留文件组选项,它将在与创建表相同的文件组中创建索引
I suggest using the first approach and leave defaults or else you can explore the options here : https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql 我建议使用第一种方法并保留默认值,否则您可以在这里浏览选项: https : //docs.microsoft.com/zh-cn/sql/t-sql/statements/create-index-transact-sql
To add a Primary Key constraint backed by a BTree index to a Heap, and store its backing index on a particular filegroup, something like: 要将由BTree索引支持的主键约束添加到堆,并将其支持索引存储在特定的文件组中,例如:
CREATE TABLE MESSAGE_LOG
(
RECORD_NO INT NOT NULL,
OTHER_COLUMN INT NOT NULL,
--. . .
CONSTRAINT MESSAGE_LOG_RECORD_PK PRIMARY KEY NONCLUSTERED (RECORD_NO) ON DATA
)
Although in SQL Server we typically use Clustered Index tables instead of heaps, just leave of NONCLUSTERED, as CLUSTERED is the default for Primary Key constraints. 尽管在SQL Server中,我们通常使用聚簇索引表而不是堆,但不要使用NONCLUSTERED,因为CLUSTERED是主键约束的默认设置。 Also each database has its own filegroups, so you don't often place tables or indexes directly on non-default filegroups. 此外,每个数据库都有其自己的文件组,因此,您通常不会将表或索引直接放置在非默认文件组上。 So typically in SQL Server you would just have: 因此,通常在SQL Server中,您只有:
CREATE TABLE MESSAGE_LOG
(
RECORD_NO INT NOT NULL,
OTHER_COLUMN INT NOT NULL,
--. . .
CONSTRAINT MESSAGE_LOG_RECORD_PK PRIMARY KEY (RECORD_NO)
)
According to this reference 根据这个参考
CONSTRAINT "MESSAGE_LOG_RECORD_PK" PRIMARY KEY ("RECORD_NO")
**USING INDEX** ... TABLESPACE "DATA" ENABLE
seems to suggest that this clause (part of CREATE/ALTER TABLE ...
- Oracle syntax) will create an UNIQUE INDEX
for a primary key constraint ( MESSAGE_LOG_RECORD_PK
). 似乎建议此子句( CREATE/ALTER TABLE ...
一部分-Oracle语法)将为主键约束( MESSAGE_LOG_RECORD_PK
)创建UNIQUE INDEX
。
(1) Default behaviour of SQL Server for disk based row store tables (main table type within SQL Server databases) is as follow: (1)对于基于磁盘的行存储表(SQL Server数据库中的主表类型),SQL Server的默认行为如下:
(1.1) It will create an UNIQUE CLUSTERED INDEX
when a PRIMARY KEY constraint is defined on a table without another CLUSTERED index. (1.1)当在没有另一个CLUSTERED索引的表上定义了PRIMARY KEY约束时,它将创建UNIQUE CLUSTERED INDEX
。
(1.2) It will create an UNIQUE NONCLUSTERED INDEX
when a PRIMARY KEY
constraint is defined on a table if that table already have an CLUSTERED index. (1.2)如果在表上定义了PRIMARY KEY
约束(如果该表已经具有CLUSTERED索引),它将创建UNIQUE NONCLUSTERED INDEX
。
(1.4) It will try to create an UNIQUE CLUSTERED
/ NONCLUSTERED
index on current table depending of PRIMARY KEY constraint options: clustered / nonclustered thus: (1.4)它将尝试根据PRIMARY KEY约束选项在当前表上创建UNIQUE CLUSTERED
/ NONCLUSTERED
索引:集群/非集群,因此:
CREATE TABLE Groups (
GroupId INT IDENTITY(1, 1) NOT NULL
CONSTRAINT PK_Groups_GroupId PRIMARY KEY CLUSTERED ON [PRIMARY] (GroupId),
...
)
Also, notice in this case the name of data SQL Server filegroup ( PRIMARY
in this case; ~ as Oracle table space I believe) used to store data of index associated with this primary key. 另外,在这种情况下,请注意用于存储与此主键关联的索引数据的数据SQL Server文件组的名称(在这种情况下为PRIMARY
;我相信是〜表为Oracle表空间)。
(2) My answer is following SQL statement that will add a PRIMARY KEY constraint defined on RECORD_NO column (which will create also an UNIQUE CLUSTERED - default - index) and also definied on DATA filegroup : (2)我的答案是下面的SQL语句,该语句将添加在RECORD_NO列上定义的PRIMARY KEY约束(这还将创建UNIQUE CLUSTERED-default-index),并且还在DATA文件组上定义:
ALTER TABLE dbo.LOG_RECORD
ADD CONSTRAINT MESSAGE_LOG_RECORD_PK
PRIMARY KEY CLUSTERED ON [DATA] (RECORD_NO)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.