We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In MS SQL Server, the correct syntax for creating a composite index involves listing the columns within parentheses, separated by commas. Composite indexes are used to create an index on multiple columns of a table. This helps in optimizing query performance that involves these columns.
Here’s the correct syntax for creating a composite index:
CREATE INDEX index_name
ON table_name (column1, column2);
CREATE INDEX index_name
ON table_name (column1, column2);
Explanation of the Options:
CREATE INDEX index_name ON table_name(column1), table_name(column2);
This syntax is incorrect because it separates the columns with a comma and mistakenly repeats the table name.
CREATE INDEX index_name ON table_name(column1) and table_name(column2);
This syntax is incorrect because it uses the word and, which is not valid in this context.
CREATE INDEX index_name ON table_name(column1, column2);
This syntax is correct. It creates a composite index on column1 and column2 within the table table_name.
All the above-mentioned syntax are correct.
This option is incorrect because not all the provided syntaxes are valid.
Conclusion
The correct syntax is:
CREATE INDEX index_name
ON table_name (column1, column2);
CREATE INDEX index_name
ON table_name (column1, column2);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Indexes - 4
You are viewing a single comment's thread. Return to all comments →
In MS SQL Server, the correct syntax for creating a composite index involves listing the columns within parentheses, separated by commas. Composite indexes are used to create an index on multiple columns of a table. This helps in optimizing query performance that involves these columns.
Here’s the correct syntax for creating a composite index:
CREATE INDEX index_name ON table_name (column1, column2);
CREATE INDEX index_name ON table_name (column1, column2);
Explanation of the Options:
Conclusion
The correct syntax is: CREATE INDEX index_name ON table_name (column1, column2);
CREATE INDEX index_name ON table_name (column1, column2);