Showing posts with label care. Show all posts
Showing posts with label care. Show all posts

Wednesday, March 21, 2012

Drop table - not possible

Hi!

I wish to drop a table on sql server 2000, but SS2K will allow it because of table's dependencies.

Is there a way to drop the table (I don't care about dependencies)? I just want to drop it!

thanks.

FaN
You have to care about dependencies like constraints, Statistics, DRI(declarative referential integrity), Views and indexes because if you have any of the above you cannot drop the table because SQL Server uses the relational model which means all related items must be removed before items in the relation can be dropped because of data integrity issues.|||

Easy.

First, remove all of the dependencies.

Second, DROP the table.

Sunday, March 11, 2012

Drop indexes

I have a database with many PK and FK constraints. Is there any script I can use to drop all indexes and rebuild them taking care of PK and dependencies? I am unable to drop them by tablename order. This is on MSSQLServer-2000 SP3. Any help is appreciated.why drop and recreate when you can defrag or reindex? have you looked at DBCC SHOWCONTIG to make you sure need to do this.

btw, you only have to do the clustered ones. the nonclustered get rebuilt when you do this.

here is some code...

SELECT 'DBCC DBREINDEX(' + CAST(o.[name] as varchar(200)) + ',' + CAST(i.[name] as varchar) + ')
GO'
FROM sysindexes i
JOIN sysobjects o
ON i.id = o.id
WHERE o.xtype = 'U'
AND i.indid = 1|||is I have primary clustered indexes on 812 tables and do not know a lot of dependencies if I go by tablename order to drop and recreate indexes. Does DBCC REINDEX drops and recreates PK indexes too? We have run DBCC showcontig and saw fragmentation quite a bit.|||DBCC DBREINDEX does not drop and recreate to knowledge but I would confirm in BOL. It does however lock up tables.

DBCC INDEXDEFRAG is slower but does not lock up the tables so much and the users can work more easily while this goes on.|||DBCC DBREINDEX does not drop and recreate to knowledge but I would confirm in BOL.
It doesn't - in fact, when last I read about all this stuff it was presented as DBREINDEX's USP :D