Reputation: 649
The syntax to create a table is
CREATE [temp] TABLE TableName(...)
so table can be created in the temp database using
CREATE temp TABLE MyTable(...)
or
CREATE TABLE temp.MyTable(...)
and the fully resolved way to refer to that table would be
temp.Mytable
which would be a different table to main.MyTable.
However, the syntax to create an index is just
CREATE INDEX IndexName ON TableName (FieldName )
which does not allow the table name to have the database name prepended
so this is OK
CREATE INDEX MyIndex ON MyTable (MyField)
but this is not
CREATE INDEX MyIndex ON Temp.MyTable (MyField)
How then can I create an index on a temp table (especially if there might be table of the same name in the main database?
Upvotes: 4
Views: 3983
Reputation: 180070
The database name must be put on the index name:
CREATE INDEX temp.MyIndex ON MyTable(MyField)
Upvotes: 8