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. I would like to know if someone could provide me and equivalence of "USING INDEX" in Sql Server.
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
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
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:
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. 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:
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
).
(1) Default behaviour of SQL Server for disk based row store tables (main table type within SQL Server databases) is as follow:
(1.1) It will create an UNIQUE CLUSTERED INDEX
when a PRIMARY KEY constraint is defined on a table without another 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.4) It will try to create an UNIQUE CLUSTERED
/ NONCLUSTERED
index on current table depending of PRIMARY KEY constraint options: clustered / nonclustered thus:
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.
(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 :
ALTER TABLE dbo.LOG_RECORD
ADD CONSTRAINT MESSAGE_LOG_RECORD_PK
PRIMARY KEY CLUSTERED ON [DATA] (RECORD_NO)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.