T-sql query...

  • hello,

    Any command is there to delete records..

    Problem,

    I have one database name is --- School

    This database have 10 tables like (Employee,salary,attendance,leaves.........).These tables have

    data..I want to delete all table records with a single query ..

    is it possible ?

    Regards:

    Dastagiri.D

    Thanks
    Dastagiri.D

  • It is not possible

    Make use of the result

    select 'delete from '+table_name from information_schema.tables

    where table_type='base table'


    Madhivanan

    Failing to plan is Planning to fail

  • Why would you even want to do this in a single statement ?

    For data integrity ?

    Then you can place the 10 delete statements within a transaction.

    It can't be so hard to type-in "DELETE FROM Table_1" 10 times and change the names.

    I sure hope you are not planning to delete the contents of tables you don't even know the name of ..

  • And be sure you have a recent backup BEFORE you run the deletes.

    -- You can't be late until you show up.

  • Of course.

    I would expect any "Senior DBA" to make a backup FIRST.

  • J (11/6/2008)


    Of course.

    I would expect any "Senior DBA" to make a backup FIRST.

    There a plenty of threads opened with the phase "I've deleted my data but don't have a backup - Please help" followed by the infamous "Urgent!" plea. I know how I would proceed but you should never assume that some of these fine posters are "Senior" or even "DBA" material.........and a re-statement of the obvious can prevent some headaches for them down the road. 😉

    -- You can't be late until you show up.

  • there is off course the undocumented :crazy: [sp_MSforeachtable].

    Keep in mind the order of execution if you have DRI.

    (or repeat more than once)

    If you want to avoid log overhead, try to use truncate table xyz

    (will not work for parent tables.)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply