Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

Create Index in MSSQL

Below are examples illustrating the creation, alteration, and deletion of an index in Microsoft SQL Server (MSSQL):

1. Creating an Index:

-- Create an index named idx_LastName on the LastName column of the Customers table

CREATE INDEX idx_LastName

ON Customers (LastName);

2. Dropping an Index:

-- Drop the index idx_LastName from the Customers table

DROP INDEX idx_LastName

ON Customers;

3. Altering a Table to Add an Index:

-- Add an index named idx_LastName on the LastName column of the Customers table

ALTER TABLE Customers

ADD INDEX idx_LastName (LastName);

4. Altering a Table to Drop an Index:

-- Drop the index idx_LastName from the Customers table using ALTER TABLE

ALTER TABLE Customers

DROP INDEX idx_LastName;

These SQL statements demonstrate the process of creating, altering, and dropping an index in MSSQL. Remember to replace Customers, LastName, and idx_LastName with your actual table name, column name, and index name, respectively. Additionally, ensure proper permissions are granted before executing these commands.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.