Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with hundred million records and which has no indexed created there.


Now i need to remove the table from production without interrupting the database.

I have tried following but it all fails,

1.) Removing constraints
2.) Truncate table
3.) Creating index for faster processing it all fails

Is there any method for quick deleting of the data?
Posted
Comments
ZurdoDev 10-Jun-15 10:46am    
The quickest way is to truncate the data.

TRUNCATE TABLE Table1

However, you'll get an error with any other method so if something isn't working, share the error so we can help.
Hetal Jariwala 11-Jun-15 2:09am    
I don't need table i have tried to drop table but it's taking too much time and also other process are getting stuck when i'm firing the query
ZurdoDev 11-Jun-15 7:29am    
Then truncate it and then drop it. I don't see any other choice.
Michael_Davies 10-Jun-15 13:14pm    
Try DROP and then CREATE if you still need the table.
Hetal Jariwala 11-Jun-15 2:05am    
I don't need table i have tried to drop table but it's taking too much time and also other process are getting stuck when i'm firing the query

1 solution

Create another table with the same schema as that of your original table and this time with all indexing set.

Once everything is ready execute a quick table rename statements on your original table to something else and rename the new table with the original table name.

This renaming tables doesn't impact performance at all.

Here are the steps to follow:
1) Create a new table "Table_A_New" with same schema as that of original table "Table_A"
2) Add required indexing to table "Table_A_New"
3) Remove any constraints on "Table_A"
4) Execute rename statement on table "Table_A"
EXEC sp_rename 'Table_A', 'Table_A_Old';
5) Execute rename statement on new table "Table_A_New" to original name
EXEC sp_rename 'Table_A_New', 'Table_A';
6) Add constraints back to "Table_A"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900