Hello, I'm creating a database and I need to create some compound indexes to optimize the bank's processing. The problem is that I do not want to have to name those indexes one-by-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 the CONSTRAINT for me for the email (UNIQUE) and password (DEFAULT) fields. The problem is when I have to create a compound 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 I can use in declaring this index so that it is automatically named? or any other way to create this composite index so it has the same result?