I have a large .sqlproj project. In one .sql file I have one table definition:
CREATE TABLE [dbo].[TableOne] (
[ColumnName] UNIQUEIDENTIFIER NULL
);
GO
CREATE UNIQUE CLUSTERED INDEX [TableOneIndex]
ON [dbo].[TableOne]([ColumnName] ASC;
In another .sql file I have another table definition:
CREATE TABLE [dbo].[TableTwo] (
[ColumnName] UNIQUEIDENTIFIER NULL
);
GO
CREATE UNIQUE CLUSTERED INDEX [TableOneIndex]
ON [dbo].[TableTwo]([ColumnName] ASC;
Note that both indices are called TableOneIndex
. Yet the project builds fine and deploys fine.
How can this be legal?
The CREATE INDEX
specifications explain this:
index_name
Is the name of the index. Index names must be unique within a table or view but do not have to be unique within a database. Index names must follow the rules of identifiers.
They have the same name in the SYS.INDEX
tables however they have complete different OBJECT_ID
's.
Look at the sys.tables
SELECT * FROM
SYS.TABLES
WHERE NAME LIKE 'TABLE%'
and then do:
SELECT * FROM SYS.INDEXES
WHERE OBJECT_ID IN (245575913
,277576027)
Where the object ID's are the ID's from the sys.tables
table relating to TableOne and TableTwo
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