I need to add an index to a table that already has the primary key indexed. The new index will be on another column.
I don't have enough permissions on this table to select 'Alter' by right clicking and selecting 'Script table as'.
Is there any way to add an index to a column without effecting any of the existing data?
myTable:
- id -- int -----> this is an identity column, set as PK and indexable
- bookid ---> varchar(20) ----> this is the column that needs index created
Yes you can. It will lock the table you're adding an index to while it's being created. If the table is large, it may take awhile as it has to read each row while building the index.
Dropping a table removes the table definition from the data dictionary. All rows of the table are no longer accessible. All indexes and triggers associated with a table are dropped.
DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. However, to drop a table that is referenced by a view or a foreign-key constraint of another table, CASCADE must be specified.
You can execute create index script as below, which is similar to what Igor mentioned
CREATE NONCLUSTERED INDEX IX_YourTable ON dbo.YourTable (bookid)
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