Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 9 of 9

Thread: SQL Bulk Delete

  1. #1
    DotNetDevelopments is offline Senior Member
    Join Date
    Jul 2008
    Location
    Harlow / Essex / UK
    Posts
    619

    Default SQL Bulk Delete

    Hi

    We want to remove a whole manufacturers range from our site and database but are unsure of the best way of doing this.

    Ideally we need to remove the product variants, then the products and then finally the manufacturer

    Is there an SQL statement that can achieve this?

    Thanks in advance.....
    =====
    Version (Code/DB): AspDotNetStorefront MSx 9.1.0.1/9.1.0.0
    Execution Mode: 64 Bit
    Dot Net Developments - E-commerce By Experience

  2. #2
    joe.loutzenhiser is offline Junior Member
    Join Date
    Jan 2008
    Location
    Ashland, OR
    Posts
    18

    Default This should do it...

    In your SQL Enterprise Mgr run the following query and make sure you see the products you want to delete:

    select * from product p
    join productmanufacturer pm on p.productid = pm.productid
    and pm.manufacturerid = (select top 1 manufacturerid from manufacturer where name = 'ManufacturerToEventuallyDelete')

    If you only see products you wish to delete, then run this:

    update product set deleted = 1 where productid in (select p.productid from product p
    join productmanufacturer pm on p.productid = pm.productid
    and pm.manufacturerid = (select top 1 manufacturerid from manufacturer where name = 'ManufacturerToEventuallyDelete'))

    update productvariant set deleted = 1 where productid in (select p.productid from product p
    join productmanufacturer pm on p.productid = pm.productid
    and pm.manufacturerid = (select top 1 manufacturerid from manufacturer where name = 'ManufacturerToEventuallyDelete'))

    update manufacturer set deleted = 1 where name = 'ManufacturerToEventuallyDelete'

    Hope that proves useful.
    Vortx - DevNet partner
    http://www.vortx.com

  3. #3
    Mike The Last Boyscout is offline User
    Join Date
    Nov 2008
    Posts
    254

    Default

    As always, please ensure that you have a full, functioning backup before making any code modifications or file changes to your AspDotNetStorefront website, or running any ad-hoc queries against your database. Improperly making code modifications or running queries against your database can cause your website to be non-functional and/or your data to be permanently lost. As part of your disaster recovery plan, you should make regular backups of all files and data, and perform periodic checks to ensure your backups function properly. If you are not sure if your data is adequately protected, contact an IT professional or your hosting provider for assistance.

  4. #4
    gleapman is offline Member
    Join Date
    Apr 2009
    Location
    Golden, CO
    Posts
    45

    Default

    I have a related question.

    When deleting a single product programatically, is it okay to just set the Deleted field to '1' in the Product table? Or are there other changes needed in the database? I see in the previous posts a suggestion of setting the deleted field in the ProductVariant table as well. Is that really necessary?

    Thanks.

  5. #5
    Rob is offline Senior Member
    Join Date
    Aug 2004
    Posts
    3,037

    Default

    well, nuking a product (deleting) it is a bit more complicated, you need to:

    a) delete the product rec
    b) delete variant recs
    c) delete (ALL) mapping recs
    d) delete extended (customer level/wholesale/retail) pricing recs
    e) have all carts updated (they might have contained it)
    f) delete product rating recs
    g) etc...

    I thought we had a proc that was able to do this?
    AspDotNetStorefront
    Shopping Cart

  6. #6
    gleapman is offline Member
    Join Date
    Apr 2009
    Location
    Golden, CO
    Posts
    45

    Default

    Thanks for the quick reply.

    I should have been clearer in my earlier post. I'm not concerned about leaving clutter in the database, I just want the product to be 'deleted' in the same way it is 'deleted' when I delete it from the admin site.

    When I delete a product from the admin site, it changes the Deleted flag in the Product table to '1' and there are no obvious changes to either the ProductVariant or ExtendedPrice tables. If I want to replicate programatically with some custom code the same changes made when I delete a product from within the admin site, is there anything I need to change in the database other than switching the deleted flag in the record in the Product table?

  7. #7
    Rob is offline Senior Member
    Join Date
    Aug 2004
    Posts
    3,037

    Default

    Nope. that's it then. Set Deleted=1 in product table.
    AspDotNetStorefront
    Shopping Cart

  8. #8
    gleapman is offline Member
    Join Date
    Apr 2009
    Location
    Golden, CO
    Posts
    45

    Default

    Thanks again. A client wants a bid on some work and I wanted to know the surprises before I lock in a price.

  9. #9
    Rob is offline Senior Member
    Join Date
    Aug 2004
    Posts
    3,037

    Default

    always wise to do
    AspDotNetStorefront
    Shopping Cart