SQL Server database, table memory, instance name parsing

Source: Internet
Author: User
Tags reserved rtrim

--Database memory analysis use Mastergodeclare @insSize TABLE (dbName sysname,checktime varchar, dbsize varchar (), logsize varchar ( INSERT into @insSize (DbName, Checktime, Dbsize, logsize) EXEC sp_msforeachdb ' select '? ' Dbname,convert (VARCHAR (19 ), GETDATE (), Checktime,ltrim (STR (filename,3) <> "LDF" then convert (Dec (15,2), size) * 8/ (15,2) (+ ELSE 0 END), + "MB") Dbsize, LTRIM (STR (Case-Right (filename,3) = "LDF" then convert (Dec (15,2), size) * 8/1024 ELSE 0 END), 15,2) + ' MB ') logsize from?. Dbo.sysfiles '--select * from @insSize ORDER by CONVERT (Decimal,ltrim (RTRIM (SUBSTRING (Dbsize,1,len)-2))) Descselect checktime as ' check Date ', dbName as ' database ', dbsize as ' data capacity ', logsize as ' log capacity ', cast (cast (left (Dbsize,len (dbsize)-2) & Nbsp;as decimal (10,2)) +cast (left (Logsize,len (logsize)-2)  as decimal (10,2)) as VARCHAR (+) + ' MB ' as ' Occupy space ' from the @insSize WHERE dbName not in (' Master ', ' model ', ' tempdb ', ' msdb ', ' distribution ') ORDER by CONVERT (Decimal,ltrim (RTRIM (SUBSTRING (Dbsize,1,len (dbsize)-2)) desc--table Space Analysis Beginuse[empi]--select count (1) from  Sysobjects the number of tables in the where xtype= ' U ' database create table #t (name varchar (255), rows bigint, reserved varchar (), data varchar (20), Index_size varchar (unused varchar) EXEC sp_msforeachtable "insert into #t exec sp_spaceused '? '" SELECT Name as ' Table name ', rows as ' data rows ', cast (cast (CAST (Data,len (data)-2 as FLOAT)/1024 as DECIMAL (10,3)) as VARCHAR () + ' MB ' as ' Occupy space ' , Cast (CAST (CAST (Reserved,len (reserved)-2 as FLOAT)/1024 as DECIMAL (10,3) as VARCHAR) + ' MB ' as ' total space reserved ', index _size as ' indexed space ', unused as ' unused space ' from the #t ORDER by CONVERT (Decimal,ltrim (RTRIM (SUBSTRING (data)-2))) Data,1,len Table #tend-User name and permissions (not all) use Mastergoselect u.name as ' username ', g.name as ' permissions ', u.default_database_name as ' default database ' from SYS.S Erver_principals u, sys.server_principals G, sys.server_role_members m where g.principal_id = m.role_principal_id and U. principal_id = m.member_principal_id Order bY 1, 2go--DB instance name SELECT @ @SERVICENAME 

  

SQL Server database, table memory, instance name parsing

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.