473,289 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

how to drop all keys & indexes

I'm trying to drop all indexes and primary keys so that i can rebuild them
(from a script created from same database on another server).

when i go to the 'generate sql scripts', it has the ability to drop or
generate all
tables. it also has the ability to generate all keys only. but i cant find
a way
to drop all of these keys...

any ideas?

tia
woody rao

Jul 20 '05 #1
1 3491

"Woody Rao" <nv*****@dreamscape.com> wrote in message
news:10*************@corp.supernews.com...
I'm trying to drop all indexes and primary keys so that i can rebuild them
(from a script created from same database on another server).

when i go to the 'generate sql scripts', it has the ability to drop or
generate all
tables. it also has the ability to generate all keys only. but i cant find a way
to drop all of these keys...

any ideas?

tia
woody rao


One way is to copy and paste the result of a query like this one (assuming
all tables are owned by dbo):

select 'alter table dbo.'+ TABLE_NAME + ' drop constraint ' +
CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where CONSTRAINT_TYPE in ('PRIMARY KEY', 'FOREIGN KEY')

This can be automated with a cursor and EXEC() if necessary, although you
may find it easier to look at a database comparison tool which will build
migration/synchronization scripts for you.

Simon
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rod Davis | last post by:
Once a week, we run a script to drop all the indexes on tables in our db, followed by another to add those indexes back (we insert every day, so we do this to prevent index fragmenttation). The...
3
by: Randell D. | last post by:
Folks, My internet access is intermitent until I get my own connection inside the next ten days - I say this so that I can thank in advance who ever gives a few seconds to read/answer my...
4
by: Sujeet | last post by:
Hey guys, I want to import a database from SQL Server 2000 to MS Access with all indices and keys along with the tables. DTS does not export indices and keys, only the structure and the data. ...
7
by: Philip | last post by:
Hey all, (Access 2000) I've been having a horror story with this design problem. My Database is Structured like This: AUTHORS, BOOKS, PAGES. Those are the Tables and each Item in each table...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
2
by: rcamarda | last post by:
Hi, I found this SQL in the news group to drop indexs in a table. I need a script that will drop all indexes in all user tables of a given database: DECLARE @indexName NVARCHAR(128) DECLARE...
3
by: db2admin | last post by:
Hello, I always assumed that dropping table will drop everything associated with it like indexes, references etc. I just noticed that after dropping table A and recreating it and then creating...
0
by: mjohnson0321 | last post by:
I am trying to incorporate a CSS drop-down menu into a site (suckerfish menu). The menu gets lost behind the content below it, but only on one of the drop downs (News). The error occurs on all of...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.