Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALTER TABLE DROP INDEX failed on a table that isn't memory optimized

I'm trying to drop an index created on a table, but I get this error -

The operation 'ALTER TABLE DROP INDEX' is supported only with memory optimized tables.

I need to remove this index in order to drop a field in my table. Is there any way of doing this without duplicating the table, and migrating all the data across?

like image 304
xalessi Avatar asked May 01 '19 09:05

xalessi


People also ask

How do I drop a memory optimized table?

Remove the server and database triggers on CREATE / DROP TABLE and CREATE / DROP PROCEDURE . Make sure there are no DDL event notifications, Memory-optimized tables and natively compiled stored procedures cannot be created or dropped if there is a server or database event notification for that DDL operation.

How do you create an index on a memory optimized table?

The syntax ALTER TABLE ... ADD/DROP/ALTER INDEX is supported only for memory-optimized tables. Without using an ALTER TABLE statement, the statements CREATE INDEX, DROP INDEX, ALTER INDEX, and PAD_INDEX are not supported for indexes on memory-optimized tables.

How many types of indexes are on memory optimized tables?

There are two types of indexes which can be created on memory optimized tables, namely a HASH index or RANGE index. A memory-optimized table must always have at least one index, although if you create a primary key on the table, this requirement will be satisfied.

Which indexes can be scannable in parallel in memory optimized table?

Starting in SQL Server 2016, the query plan for a memory-optimized table can scan the table in parallel. This improves the performance of analytical queries. Hash indexes also became scannable in parallel in SQL Server 2016. Nonclustered indexes also became scannable in parallel in SQL Server 2016.


4 Answers

For regular tables you should use DROP INDEX syntax:

DROP INDEX index_name ON tab_name;

ALTER TABLE

The syntax ALTER TABLE ... ADD/DROP/ALTER INDEX is supported only for memory-optimized tables.

like image 61
Lukasz Szozda Avatar answered Oct 12 '22 17:10

Lukasz Szozda


To Drop an Index

DROP INDEX index_name ON table_name

To Add an Index

CREATE INDEX index_name ON table_name(column1, column2, ...);
like image 24
Suraj Tiwari Avatar answered Oct 12 '22 18:10

Suraj Tiwari


Drop index on memory optimized table can be done only using alter table statement

Alter table table name DROP INDEX index name

or non memory optimized tables

DROP INDEX index name ON table name

Memory optimized tables are being supported from sql server 2016.

like image 4
Romil Kumar Jain Avatar answered Oct 12 '22 19:10

Romil Kumar Jain


Look here: if it is NOT a memory optimized table then just use the "drop index" statement.

like image 1
wosi Avatar answered Oct 12 '22 18:10

wosi