sql - Delete all table data in a set [DB].[audit].[tables] -


So, I have a database with about 100 audit tables and I want to prefix them in 1 SQL query. There are 2 set tables in the database [Audit] and [DBO] I am also not convinced that these groups of tables should be called so that finding any results from Google is proving difficult.

Any suggestions?

You can find all the tables with a certain schema name such as:

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

With a cursor, you iterate over those tables, and empt it by using:

  Declare Usage DB Declare @ Query Morality (max) @ Tablename nvarchar (maximum) Declared @curs cursor select from sys.tables @curs = for cursor = cursor where schema_name (schema_id) = 'Audit' open @ Incurred @ bring @tablename circle time @@ FETCH_STATUS = 0 begin set @ query = Antrenket table audit. Close the @tablename end @tablename exec sp_executesql @query fritter @ circus @curs deallocate @curs  

If you want to delete tables instead, use this:

  set @query = N'drop table audit. '+ @tablename  

Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -