dbTalk Databases Forums  

create table

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss create table in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hayko98
 
Posts: n/a

Default create table - 11-10-2009 , 02:55 PM






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

Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: create table - 11-10-2009 , 08:55 PM






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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.