Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create table

0 views
Skip to first unread message

hayko98

unread,
Nov 10, 2009, 3:55:34 PM11/10/09
to
I am trying to create new table.APPUSER_ID has AppUserPerm_AppUser_fk
and there is NONCLUSTERED INDEX .What is the correct syntax to put
these two together?


CREATE TABLE [dbo].[APPUSER_PERM]
(
[ID] [int] NOT NULL CONSTRAINT [IX_PK_APPUSER_PERM_ID] PRIMARY KEY
CLUSTERED,
[APPUSER_ID] [int] NULL CONSTRAINT [AppUserPerm_AppUser_fk] FOREIGN
KEY REFERENCES [dbo].[APPUSER] ([ID]),

--CREATE NONCLUSTERED INDEX [IX_APPUSER_PERM_APPUSER_ID] ON [dbo].
[APPUSER_PERM] ([APPUSER_ID]) ON [PRIMARY]
[RAA_ID] [int] NULL,
) ON [PRIMARY]


Thanks in advance

Plamen Ratchev

unread,
Nov 10, 2009, 9:55:07 PM11/10/09
to
If I understand correctly you want to include the creation of the nonclustered index in the CREATE TABLE statement. The
CREATE TABLE statement only allows you to specify column or table constraints (PRIMARY KEY or UNIQUE) and since they are
enforced by an index you can additionally specify CLUSTERED or NONCLUSTERED. But you cannot explicitly create an index.
If the two columns in the index that you want to create can serve as unique combination, then an UNIQUE constraint can
be used to create the index indirectly. Here is example:

CREATE TABLE AppUser_Perm (
id INT NOT NULL CONSTRAINT pk_appuser_perm PRIMARY KEY,
appuser_perm INT NOT NULL,
raa_id INT NOT NULL,
CONSTRAINT un_appuser_perm
UNIQUE (appuser_perm, raa_id));

--
Plamen Ratchev
http://www.SQLStudio.com

0 new messages