Reputation: 18746
I'd like to create a table:
CREATE TABLE sfc.OpenId (
Url VARCHAR(255) PRIMARY KEY,
UserGuid uniqueidentifier NOT NULL references dbo.aspnet_users(userId),
)
...with an index on UserGuid.
Is it possible to create that index in the create table statement?
Upvotes: 2
Views: 2550
Reputation: 12704
Can you clarify why?
You can use transactions with DDL in SQL server and for most purposes this is equivalent to doing it at the same time.
Upvotes: 1
Reputation: 332571
Is it possible to create that index in the create table statement?
No, only constraints can be created within the CREATE TABLE syntax.
f not defined otherwise, the primary key will automatically be a CLUSTERED index - but that doesn't cover the userguid
column. The CREATE INDEX syntax needs to be a separate statement otherwise.
Upvotes: 1
Reputation: 625
You can do that if the index on UserGuid is a unique index, via UNIQUE constraint. Otherwise, no.
Upvotes: 2