How To Get Database Size Using Sql Statements?

Jun 15, 2004

How can I get database size using sql statements or system store procedures? Thanks in advance!

View 2 Replies


ADVERTISEMENT

Table Size And Database Size

Mar 2, 2008

Hi,
i use this script that show me the size of each table and do the sum of all the table size.

SELECT
X.[name],
REPLACE(CONVERT(varchar, CONVERT(money, X.[rows]), 1), '.00', '') AS [rows],
REPLACE(CONVERT(varchar, CONVERT(money, X.[reserved]), 1), '.00', '') AS [reserved],
REPLACE(CONVERT(varchar, CONVERT(money, X.[data]), 1), '.00', '') AS [data],
REPLACE(CONVERT(varchar, CONVERT(money, X.[index_size]), 1), '.00', '') AS [index_size],
REPLACE(CONVERT(varchar, CONVERT(money, X.[unused]), 1), '.00', '') AS [unused]
FROM
(SELECT
CAST(object_name(id) AS varchar(50)) AS [name],
SUM(CASE WHEN indid < 2 THEN CONVERT(bigint, [rows]) END) AS [rows],
SUM(CONVERT(bigint, reserved)) * 8 AS reserved,
SUM(CONVERT(bigint, dpages)) * 8 AS data,
SUM(CONVERT(bigint, used) - CONVERT(bigint, dpages)) * 8 AS index_size,
SUM(CONVERT(bigint, reserved) - CONVERT(bigint, used)) * 8 AS unused
FROM sysindexes WITH (NOLOCK)
WHERE sysindexes.indid IN (0, 1, 255)
AND sysindexes.id > 100
AND object_name(sysindexes.id) <> 'dtproperties'
GROUP BY sysindexes.id WITH ROLLUP) AS X
ORDER BY X.[name]

the problem is that the sum of all tables is not the same size when i make a full database backup.
example of this is when i run this query against my database i see a sum of 111,899 KB that they are 111MB,but when
i do full backup to that database the size of this full backup is 1.5GB,why is that and where this size come from?

THX

View 5 Replies View Related

Right Code Statements Of SqlConnection &&amp; ConnectionString For Connecting A Database In Database Explorer Of VB 2005 Express?

Feb 14, 2008

Hi all,

In the VB 2005 Express, I can get the SqlConnection and ConnectionString of a Database "shcDB" in the Object Explorer of SQL Server Management Studio Express (SSMSE) by the following set of code:
///--CallshcSpAdoNetVB2005.vb--////

Imports System.Data

Imports System.Data.SqlClient

Imports System.Data.SqlTypes

Public Class Form1

Public Sub InsertNewFriend()

Dim connectionString As String = "Data Source=.SQLEXPRESS;Initial Catalog=shcDB;Integrated Security=SSPI;"

Dim connection As SqlConnection = New SqlConnection(connectionString)

Try

connection.Open()

Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)

command.CommandType = CommandType.StoredProcedure
.......................................
etc.
///////////////////////////////////////////////////////
If the Database "shcDB" and the Stored Procedure "sp_inertNewRecord" are in the Database Explorer of VB 2005 Express, I plan to use "Data Source=local" in the following code statements to get the SqlConnection and ConnectionString:
.........................
........................

Dim connectionString As String = "Data Source=local;Initial Catalog=shcDB;Integrated Security=SSPI;"

Dim connection As SqlConnection = New SqlConnection(connectionString)

Try

connection.Open()

Dim command As SqlCommand = New SqlCommand("sp_insertNewRecord", connection)

command.CommandType = CommandType.StoredProcedure
........................
etc.

Is the "Data Source=local" statement right for this case? If not, what is the right code statement for my case?

Please help and advise.

Thanks,
Scott Chang

View 6 Replies View Related

SQL 2005 Resize Initial Log Size: MODIFY FILE Failed. Specified Size Is Less Than Current Size.

Sep 4, 2007


I am trying to resize a database initial log file from 500M to 2M. I€™m using€?

ALTER DATABASE <DBNAME> MODIFY FILE ( NAME = <DBLOGFILENAME, SIZE = 2 ) "



And I'm getting "MODIFY FILE failed. Specified size is less than current size." I tried going into the database properties and setting the log file to 2M, but it doesn€™t keep the changes.



Any help with this process?

View 1 Replies View Related

Executing SQL Statements In Another Database

Apr 9, 2008

I have a stored procedure named usp_CreateSomeAdminObjects that resides in say a database named AdminStuff (ok, fictional but it gets the point across :) ). This proc generates a series of dynamic SQL statements (DROP TRIGGER, CREATE TRIGGER and EXECUTE sp_settriggerorder) against tables that reside in different databases. However I am unable to change the context of the database from AdminStuff to the database I am cycling. Any suggestions on how I can have execute this dynamic SQL in the context of a specific database (other than the one the proc resides in)?

I can not put the USE statement in a stored procedure. Attempts to use sp_executesql, EXECUTE and even run the script through sqlcmd using either (a) the -d option or (b) a USE <dbname>; statement as part of the -q parameter have all been unsuccessful.

Heck, even if I execute this code through SSMS it does not work as I need it to:

USE OtherDatabaseName;
EXEC DBA.dbo.usp_CreateSomeAdminObjects

I confirmed this by adding these statements to the proc:

/* Gets list of tables from the current database */
SELECT name, create_date FROM sys.objects WHERE type = 'U' ORDER BY name

SELECT DB_NAME();

These statements return a list of user tables that reside in AdminStuff and not OtherDatabaseName (the same goes for the DB_NAME() statement.

Any suggestions on how I can accomplish what I'm looking to do - have this proc execute dynamically generated DDL scripts for tables that reside in a different database. I'd rather not name this procedure sp_CreateSomeAdminObjects and compile it in the master database. If that is my only option I will but figured I'd check out other options first.

View 10 Replies View Related

Getting Database Size And Log Size

Aug 11, 2000

Hi,
I am using
exec sp_helpdb
go
dbcc sqlperf(logspace) for
getting database size and log size. Is this gives the correct
database size and log size or Is there any other way to get the logsize and database size by means of query analyzer.

Thanks in Advance.

Seenu. S

View 4 Replies View Related

Should I Add Lock Statements To My Database Write Querys

Jun 5, 2008

Hello,Could some clarify for me? I’ve been told that I should add  lock statements  to my database write querys (update, delete, insert). I’m not sure If it’s necessary though. The only documentation I’ve found so far is how to implement a lock statement with threading but I’m not using the threading namespace. What best practice and how would I implement this without threading or should I be using threading?Thanks in advance!
 

View 4 Replies View Related

Retrieving 'CREATE' Statements For Database Objects

May 6, 2008

MySql has a statement like:
SHOW CREATE TABLE tablename;

that returns the precise CREATE TABLE statement for the specified tablename.

Sql Management Studio also allows scripting Create Statement for any object by right-clicking it.
But I want to do this programatically, and fetch CREATE statements for Tables, Procedures & Views.

How can I retrive CREATE statements for Database objects progrmatically in Sql Server???

View 9 Replies View Related

The Database File Is Larger Than The Configured Maximum Database Size.

Mar 20, 2007

I'm getting this error while trying to insert records into a SQL Server Compact Edition database. I have pasted my connection string that was used when creating the database as well as for accessing that same database from my Windows application.

Thanks for any help any of you can give!

Data Source=OnTheGo.sdf;Encrypt Database=True;Password=<password>;Max Database Size=4091

View 3 Replies View Related

Help In Creating Insert Statements For Retreiving Data From Database

Apr 14, 2008



Hi all,


Could someone tell me how to get the data from all tables of the database in the form of insert script? We are moving our databse from SQL Server 2000 to SQL Server 2005. The scripts for the Database, Tables, Views , Procedures, Functions have been obtained and it is only the data that is remaining. Some are small tables with 5 to 6 columns but there are some with 50 odd columns. A friend of mine told me about a procedure that returns a dataset with INSERT statements by passing a table name as a parameter. Such procedure would be of great help.

Thank you

View 5 Replies View Related

Database File Is Larger Than The Configured Max Database Size.

Feb 18, 2008

Hello,

I am developing a smart device application with Visual Studio .Net 2005 and SQL Server Compact Edition database. And also using merge replication to synchronize the data from the mobile device to the SQL Server.

My database size is around 350MB. So when I am trying to synchronize this is the error message that I get.
" The database file is larger than the configured maximum database size. The setting takes effect on the first concurrent database connection only.[Required Max Database size ( in MB; 0 if unknown)=129].

I tried changing the Max database size in the connection string and my connection string looks as follows and still did not have any luck.

connstr= "Data Source=Storage CardItems.sdf;Max Database Size=500;"

Any help regarding this would be appreciated.

Thank you
.

View 6 Replies View Related

Transact SQL :: How To Find Stored Procedures Without NOLOCK Statements In Database

Jun 15, 2015

I need to list out all the procedures which have select queries and does not use NOLOCK hint. Please note that there are more than 2000 sps and some sps have single select some have multiple, some does not have select queries at all. I need to find out only the ones which does not use NOLOCK hint in a select query.

View 8 Replies View Related

SQL Security :: Database Level Audit - Query Parameters For SELECT Statements

Aug 31, 2015

I have setup a Database Audit Specification as follows:

Audit Action Type: SELECT | Object Class: DATABASE | Object Name: SHOPDB | Principal Name: public

Now, when I perform a SELECT query with a bound parameter such as:

SELECT * FROM myTable WHERE name='queryname'

What I see through the Audit Logs is something like:

SELECT * FROM myTable WHERE name='@1'

I understand that it is by design that we cannot see these parameters throught Database Level Auditing. I would like to know whether it is possible to see these parameters by any other means using

(1) SQL Server Enterprise Edition,
(2) SQL Server Standard Edition, or
(3) by an external tool.

View 9 Replies View Related

Database Log Size

Jun 7, 2007

hi
my database on remote server i cannot access directly.
i can access it only with query analyzer.
my log file size is 9mb but nothing in database. only few tables there so how i can reduce log file size with query.
 
thanks

View 4 Replies View Related

How To Get The SQL Database Size

Jul 15, 2004

Is it possible to get the SQL Server database size programmatically?
I have an WEB application in c# ASP NET, but I can found any information about.

Thanks for your attention

Freedeveloper

View 2 Replies View Related

Database Size

Mar 1, 2002

We have a SQL server database most time for read only because the data source comes from another database( which is not SQL server database, now it is about 2G). Every day we have a job running as following:
Step 0. extra the data from another database, and create plain text files for each table for BCP job.
Step 1. drop all of the index
Step 2. truncate all of the tables.
Step 3. BCP in all of the data from plain text file.
Step 4. create all of the index again
Step 5. shirnk the database.

Everything runs fine but the database grows 1 G from yesterday's database. I am sure we do not have so much data entry in one day.
Any one can give some suggestion?
I wonder if I need do shirnk the database or shirnk the data file before create the index.
How can know how much size for all of the index file?
Thank you very much.
Judy

View 1 Replies View Related

SQL 7 Database Size

May 4, 2001

I am a beginner with sql and I have been inputting data (txt files) to my database and now have approached 4GB in size and it will not let me expand any further on the primary file group. My 'boss' said that sql has no size. I am using desktop

View 4 Replies View Related

Database Size

Aug 13, 2001

Is there a stored procedure that returns the current size of a database, and the maximum size of a database whose growth property IS NOT set to unlimited?

TIA,

Chris

View 1 Replies View Related

Max Size Of A SQL Database

Jul 25, 2000

Just wondering if anyone knew the maximum size of a database that SQL Server 7 can handle.

joe

View 1 Replies View Related

Database Size

May 9, 2000

When I run sp_spaceused on my database it give me a total size of 258MB
The backup of this database reads 226MB
The Properties screen tells me that my data is a total of 278MB
I am running SQL 7.0 .
Why am I getting different sizes?

View 2 Replies View Related

Database Size ?

Mar 30, 2000

I have a simple question, why Am I running out of space with my current 3.5GB database, I am constantly expanding it, yet when I dump the database nightly the dump is just around 1.5GB?

View 1 Replies View Related

Database Size

Dec 17, 2002

Newbie here ....I started with a datbase of 90 megs...it now grew to 300 megs in 2 months...what is the best way to see the largest table or to find out why this database grew so fast? Thanks!

View 3 Replies View Related

Database Size

Jul 6, 2003

Hi..
My database data file are over 2.1 Gbs now. can anyone tell me is my data file too big?? or not safe?? or there's a limite for MSSQL 2000. my last choice are move some data to another database. but i have consider the report i have to make. so i really dont want to do that. can anyone advice. thanks

View 4 Replies View Related

Database Size

Aug 27, 2003

Hi,
I have 30 servers and about 600 databases. I want to know the size of databases ( data files as will log files) both used and allocated space.
Can any one tell me the easiest way to get this information?

Thanks.

View 7 Replies View Related

Database Size

Jul 27, 1999

Hi all,
We are using sql6.5. srvpack 3.
I noticed that one of our database was maxed out, and increased the size of the device and then increased the size of the database.
when I checked the database it is still showing the database is maxed out. I did it twice, it still shows that the space has been used.
Can anyone please explain to me why this is happening and how to get the actual space measurement.
Thanks in advance.

View 2 Replies View Related

Database Size

Nov 13, 1998

After we ran sp_spaceused on one database, the size for the UNUSED column is a negative number -1324KB. Can someone explain how this could happen? I really appreciate.

View 1 Replies View Related

Database Log Size

Aug 20, 2001

Hi,

I need to check the log size of my database periodically and send a notification if the size exceeds 8 GB. I want to set this up as job that runs every 30 minutes or so and page the DBA if it exceeds the above said limit. Can anyone give me the command which can be used to obtain the logsize into a variable. I am new to SQL and would appreciate your expert advise.

Thanks,
Marcus

View 1 Replies View Related

Database Size

Jan 2, 2006

Hi,
Someone can telle how with a query can i get the use size of all my db of akll my server.

I use the table sysfiles but is the total size of my file and not the use size.

Thanks a lot and happy new year.

Best regards.

View 2 Replies View Related

Database Size

May 4, 2006

Is there any shortest way to database size (data & log)

I refer to Article ID: 256650 (reduce log file size)
Quit a lot of step

I want to reduce physical occupied HDD size

View 2 Replies View Related

Database Size

Nov 5, 2007

Is there any way I can join all the information produced by this into a single output rather than multiple outputs

EXEC sp_MSforeachtable @command1=" EXEC sp_spaceused '?'"


Like this
Listing_Images43 16 KB8 KB8 KB0 KB
User 3 16 KB 8 KB 8 KB 0 KB

I want to fill a gridview in ASP but don't know how to deal with data produced through multiple queries

View 3 Replies View Related

Database Size

Apr 24, 2008

Hi All,

Will the database size decrease once I delete data from the audit tables?

View 3 Replies View Related

Database Size

May 18, 2004

I want how can i do to do capacity planning in sqlserver 2000.
Do you make scripts (vbs) who query the sysfiles tables and transfer the answer in excel ?
Please help me.
Phil

View 3 Replies View Related

Size Of Database

Jun 1, 2008

I have a database that is almost 1.55 GB in size according to the database properties window.

However I checked the size of all the tables and indexes using the stored procedure 'sp_spaceused' and the sysindexes table and the total size of all tables and indexes is only 162 Mb.

Does anyone know why the database is so big, and how I may be able to reduce the size of it?



Steve

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved