Is it possible to create indexes(no foreign keys and not unique) and table( not a table variable ) with just one SQL statement like this.
CREATE TABLE tabind
(
    id          int             identity(1,1) primary key   ,
    birthday    datetime        default getdate()           ,
    some_id     int             INDEX index_name, /*this line causes a sql server error*/
    name        nvarchar(100)
);
In fact the equivalent of this statements:
CREATE TABLE tabind
(
    id          int             identity(1,1) primary key   ,
    birthday    datetime        default getdate()           ,
    some_id int             ,
    name        nvarchar(100)
);
create index idx_tabind on tabind(some_id);
My SQL Server Version is 2012.
Thanks.
No, the in-line index declaration is 2014 only.
This actually creates the same index though.
CREATE TABLE tabind
  (
     id       INT IDENTITY(1, 1) PRIMARY KEY,
     birthday DATETIME DEFAULT GETDATE(),
     some_id  INT,
     NAME     NVARCHAR(100),
     CONSTRAINT index_name UNIQUE (NAME, id)
  ); 
SQL Server silently makes non unique non clustered indexes unique by adding in the clustered index key (implicitly created by the PK in your case)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With