Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 412063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:02:54+00:00 2026-05-12T18:02:54+00:00

So, I have a database with around 100 audit tables and I want to

  • 0

So, I have a database with around 100 audit tables and I want to empty them out preferably in 1 sql query. The database has 2 sets of tables [audit] and [dbo]. I’m not even sure what I should be calling these groups of tables so finding any kind of results from google is proving difficult.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:02:54+00:00Added an answer on May 12, 2026 at 6:02 pm

    You can find all tables with a certain schema name like:

    select name from sys.tables where schema_name(schema_id) = 'audit'
    

    With a cursor, you iterate over those tables, and empty them using TRUNCATE TABLE:

    use db
    declare @query nvarchar(max)
    declare @tablename nvarchar(max)
    declare @curs cursor
    set @curs = cursor for select name from sys.tables 
        where schema_name(schema_id) = 'audit'
    open @curs
    fetch next from @curs into @tablename
    while @@FETCH_STATUS = 0
     begin
     set @query = N'truncate table audit.' + @tablename
     exec sp_executesql @query
     fetch next from @curs into @tablename
     end
    close @curs
    deallocate @curs
    

    If you want to delete the tables instead, use:

    set @query = N'drop table audit.' + @tablename
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has around 10k records and some of them contain
We have around 100 database migration files. Many of them make schema changes which
My database has around 100 tables and anywhere from 1,000 to 20,000 rows per
I have a SQL 2000 database with around 10 million rows and I need
I have database with multiple tables in Microsoft SQL Server with schema in tables
I have around 100 computers and few workers on each of them. The already
I have a table with around 100,000 rows at the moment. I want to
We have a database that has more than 70 tables with more than 10k
I have some legacy DB with many tables (around 100) the old system is
We have a live MySQL database that is 99% INSERTs, around 100 per second.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.