0
Hello, I am creating a database and need to create some compound Index to optimize the bank processing. The problem is that I don’t want to have to name these Indexes one-on-one. Normally, I create a table as follows:
CREATE TABLE Usuario (
id INT NOT NULL IDENTITY PRIMARY KEY,
email NVARCHAR(100) NOT NULL UNIQUE,
senha NVARCHAR(100) NOT NULL DEFAULT '123',
)
When creating this table, Sqlserver automatically generates for me the CONSTRAINT for the email (UNIQUE) and password (DEFAULT) fields. The problem is when I have to create a composite index, as in the example below:
CREATE TABLE Foo (
id INT NOT NULL IDENTITY PRIMARY KEY
);
CREATE TABLE Bar (
id INT NOT NULL IDENTITY PRIMARY KEY
);
CREATE TABLE Bin (
id INT NOT NULL IDENTITY PRIMARY KEY,
FooId INT NOT NULL FOREIGN KEY REFERENCES Foo(id),
BarId INT NOT NULL FOREIGN KEY REFERENCES Bar(id)
);
CREATE UNIQUE INDEX [UX_Bin_FooIdBarId] ON Bin(FooId, BarId);
Is there any form or statement or wildcard character that I can use in the declaration of that index for it to be named automatically? or else some other way to create this composite index so that it has the same result?
Excellent. Thank you very much! It sucks to have to keep naming these references... rs
– LeandroLuk