Showing posts with label index. Show all posts
Showing posts with label index. Show all posts

Sunday, March 25, 2012

Deleting Indexes from a table

I am using SQL-DMO to loop through the Index collection and executing the
Remove method to delete indexses in a table. I am getting an error message
that says I can't delete an Index because it was created using 'PRIMARY KEY'
.
I need to be able to remove ALL Indexes from a table. Can I do this with
SQL-DMO?
Or how can I use SQL-DMO tor remove the PRIMARY KEY setting?
adv-thanks-anceJD,
You can't remove an index associated with a PRIMARY KEY constraint without
removing the PK constraint itself. So I think you'll either have to drop
the constraint and recreated it or if you just want to rebuild the index use
DBCC DBREINDEX instead.
HTH
Jerry
"JD" <JD@.discussions.microsoft.com> wrote in message
news:FDDB7221-2A65-4F8C-BB6A-1B9B931EC9B5@.microsoft.com...
>I am using SQL-DMO to loop through the Index collection and executing the
> Remove method to delete indexses in a table. I am getting an error
> message
> that says I can't delete an Index because it was created using 'PRIMARY
> KEY'.
> I need to be able to remove ALL Indexes from a table. Can I do this with
> SQL-DMO?
> Or how can I use SQL-DMO tor remove the PRIMARY KEY setting?
> adv-thanks-ance|||You will have to remove first all foreign key constraints, then all primary
key and unique constraints and then you will be able to drop the rest of the
indexes.
AMB
"JD" wrote:

> I am using SQL-DMO to loop through the Index collection and executing the
> Remove method to delete indexses in a table. I am getting an error messag
e
> that says I can't delete an Index because it was created using 'PRIMARY KE
Y'.
> I need to be able to remove ALL Indexes from a table. Can I do this with
> SQL-DMO?
> Or how can I use SQL-DMO tor remove the PRIMARY KEY setting?
> adv-thanks-ance|||Thanks,
Can you remove the PK constraint using SQL-DMO? Or will I have to write
a procedure that loops through all of the tables and remove the PK Constrain
t?
"Jerry Spivey" wrote:

> JD,
> You can't remove an index associated with a PRIMARY KEY constraint without
> removing the PK constraint itself. So I think you'll either have to drop
> the constraint and recreated it or if you just want to rebuild the index u
se
> DBCC DBREINDEX instead.
> HTH
> Jerry
> "JD" <JD@.discussions.microsoft.com> wrote in message
> news:FDDB7221-2A65-4F8C-BB6A-1B9B931EC9B5@.microsoft.com...
>
>|||JD,
I haven't actually used it before but there is a KEY object in SQL-DMO that
I believe will do what you're asking. See 'Key Object' in the SQL Server
Books Online. Also, be sure to read Alejandro's feedback as well if you
have RI established with FOREIGN KEYs to your PRIMARY KEYS.
HTH
Jerry
"JD" <JD@.discussions.microsoft.com> wrote in message
news:55256CBF-6AE1-437F-B3FB-087C67670AB7@.microsoft.com...
> Thanks,
> Can you remove the PK constraint using SQL-DMO? Or will I have to write
> a procedure that loops through all of the tables and remove the PK
> Constraint?
> "Jerry Spivey" wrote:
>|||Thanks for the help!
"Jerry Spivey" wrote:

> JD,
> I haven't actually used it before but there is a KEY object in SQL-DMO tha
t
> I believe will do what you're asking. See 'Key Object' in the SQL Server
> Books Online. Also, be sure to read Alejandro's feedback as well if you
> have RI established with FOREIGN KEYs to your PRIMARY KEYS.
> HTH
> Jerry
> "JD" <JD@.discussions.microsoft.com> wrote in message
> news:55256CBF-6AE1-437F-B3FB-087C67670AB7@.microsoft.com...
>
>|||Thanks for your help!
"Alejandro Mesa" wrote:
> You will have to remove first all foreign key constraints, then all primar
y
> key and unique constraints and then you will be able to drop the rest of t
he
> indexes.
>
> AMB
> "JD" wrote:
>sql

Wednesday, March 7, 2012

Delete with no LOG?

Hi Freinds,
SQL 2000
I have to delete 8,000,000 record from a teble which has 45,000,000 records.
There are index files also with that table.
Is there any option to delete with no logging? I already changed my SQL
DATABASE type to simple, but again it take long time to delete 8000000
records, just because it is logging it.
Thanks,
PatDrop all of the foreign key references to the table, use Truncate Table
<tableName> and then re-create the references.
Thomas
"Patrick" <patriarck@.gmail.com> wrote in message
news:ekP8eaoWFHA.3184@.TK2MSFTNGP15.phx.gbl...
> Hi Freinds,
> SQL 2000
> I have to delete 8,000,000 record from a teble which has 45,000,000 record
s.
> There are index files also with that table.
> Is there any option to delete with no logging? I already changed my SQL
> DATABASE type to simple, but again it take long time to delete 8000000
> records, just because it is logging it.
> Thanks,
> Pat
>|||Patrick
Divide the transaction into small ones
SET ROWCOUNT 10000 --Instead of 8000000
WHILE 1 = 1
BEGIN
--DELETE FROM Table WHERE .......
IF @.@.ROWCOUNT = 0
BEGIN
BREAK
END
END
SET ROWCOUNT 0
"Patrick" <patriarck@.gmail.com> wrote in message
news:ekP8eaoWFHA.3184@.TK2MSFTNGP15.phx.gbl...
> Hi Freinds,
> SQL 2000
> I have to delete 8,000,000 record from a teble which has 45,000,000
records.
> There are index files also with that table.
> Is there any option to delete with no logging? I already changed my SQL
> DATABASE type to simple, but again it take long time to delete 8000000
> records, just because it is logging it.
> Thanks,
> Pat
>