473,396 Members | 2,093 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,396 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 3499

"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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.