SQL Server: Sys.tables for bulk deletion of tables, fast statistics of multiple table records and

Source: Internet
Author: User

SQL Server: Bulk Delete table via sys.tables, or roll back table

1 beginTry2     Drop Table#temp103 EndTry4 beginCatch5 EndCatch6 7 Select 'drop/*truncate*/table tuning.'+Name asDroptable,row_number () Over(Order  byName asRowNumber8  into#temp109  fromSys.tableswhereName like 'member%'  andSchema_name (schema_id)='dbo'Ten  One Select *  from#temp10 A  - Declare @rownumber int; - Declare @records int; the Declare @droptable  nvarchar( -); -  - Select @records=MAX(RowNumber) from#temp10 -  + Set @rownumber=1; -  +  while @rownumber<=@records  A begin  at     Select @droptable =Droptable from#temp10whereRowNumber=@rownumber -     Print @droptable -     execsp_executesql@droptable -      -     Set @rownumber=@rownumber+1; - End

Dynamic statistics Database, the number of records inserted in a table per second

1 Declare @records int;2   3  while 0=04 begin 5     waitforDelay'00:00:01'   --1s per interval, executed once6    7     Select @records=IsNull(sum(T10.rows),0)8      fromSys.partitions asT109         Inner JoinSys.objects asT11 onT10.object_id=T11.object_idTen     whereT11.name like 'member%'  One      andT10.partition_number=2 --The current data is inserted into that partition and the partition is written. If there is no partition, the condition can be added without A      andt10.index_id>=2 -      -     Print @records the End

SQL Server: Sys.tables for bulk deletion of tables, fast statistics of multiple table records and

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.