Showing posts with label dear. Show all posts
Showing posts with label dear. Show all posts

Sunday, March 25, 2012

Database files free space (SQL Server 2005)

Dear friends

I need to report the amount of free space in each datafile of a database.

I have tried sys.dm_db_file_space_usage , but the documentation says that it only works for the TempDB.

Please help.

Regards

Parviz

Take a look at the sp_spaceused text. You should be able to derive from there.

exec sp_helptext 'sp_spaceused'|||

Thanks for the fast reply, but please note that sp_spaceused returns the free space for the whole database files including the LOG file. I need the info fo each file in a database seperately.

If you have a look at summary reports for a database (SQL 2005 SSMS),you would see a table and a pie chart showng the status for each file.

Thanks again.

Parviz

|||Yup. sp_spacedused can be used to get the data file usage. You can then use 'dbcc sqlperf(logspace)' to get the log usage.|||

Here's some code, cribbed from a sqldbatips report designed to mimic the taskpad in SSMS. (http://sqlblogcasts.com/blogs/sqldbatips/archive/2006/11/21/custom-ssms-reports-in-sp2-enterprise-manager-taskpad-view.aspx). All I did was add some code to show the amount free. Seems to work well. Posting here because this was one of the top results in Google when I went looking for code myself.

create table #data(Fileid int NOT NULL,

[FileGroup] int NOT NULL,

TotalExtents int NOT NULL,

UsedExtents int NOT NULL,

[Name] sysname NOT NULL,

[FileName] varchar(300) NOT NULL)

create table #log(dbname sysname NOT NULL,

LogSize numeric(15,7) NOT NULL,

LogUsed numeric(9,5) NOT NULL,

Status int NOT NULL)

insert #data exec('DBCC showfilestats with no_infomsgs')

insert #log exec('dbcc sqlperf(logspace) with no_infomsgs')

select [type], [name], totalmb, usedmb, totalmb - usedmb as EmptySpace from

(

select 'DATA' as [Type],[Name],(TotalExtents*64)/1024.0 as [TotalMB],(UsedExtents*64)/1024.0 as [UsedMB]

from #data

union all

select 'LOG',db_name()+' LOG',LogSize,((LogUsed/100)*LogSize) from #log where dbname = db_name()

--order by [Type],[Name]

)a

order by [Type],[Name]

drop table #data

drop table #log

|||

This will work for you:

-- Individual File Size query

SELECT name AS 'File Name' , physical_name AS 'Physical Name', size/128 AS 'Total Size in MB',

size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', *

FROM sys.database_files;

Database files free space (SQL Server 2005)

Dear friends

I need to report the amount of free space in each datafile of a database.

I have tried sys.dm_db_file_space_usage , but the documentation says that it only works for the TempDB.

Please help.

Regards

Parviz

Take a look at the sp_spaceused text. You should be able to derive from there.

exec sp_helptext 'sp_spaceused'|||

Thanks for the fast reply, but please note that sp_spaceused returns the free space for the whole database files including the LOG file. I need the info fo each file in a database seperately.

If you have a look at summary reports for a database (SQL 2005 SSMS),you would see a table and a pie chart showng the status for each file.

Thanks again.

Parviz

|||Yup. sp_spacedused can be used to get the data file usage. You can then use 'dbcc sqlperf(logspace)' to get the log usage.|||

Here's some code, cribbed from a sqldbatips report designed to mimic the taskpad in SSMS. (http://sqlblogcasts.com/blogs/sqldbatips/archive/2006/11/21/custom-ssms-reports-in-sp2-enterprise-manager-taskpad-view.aspx). All I did was add some code to show the amount free. Seems to work well. Posting here because this was one of the top results in Google when I went looking for code myself.

create table #data(Fileid int NOT NULL,

[FileGroup] int NOT NULL,

TotalExtents int NOT NULL,

UsedExtents int NOT NULL,

[Name] sysname NOT NULL,

[FileName] varchar(300) NOT NULL)

create table #log(dbname sysname NOT NULL,

LogSize numeric(15,7) NOT NULL,

LogUsed numeric(9,5) NOT NULL,

Status int NOT NULL)

insert #data exec('DBCC showfilestats with no_infomsgs')

insert #log exec('dbcc sqlperf(logspace) with no_infomsgs')

select [type], [name], totalmb, usedmb, totalmb - usedmb as EmptySpace from

(

select 'DATA' as [Type],[Name],(TotalExtents*64)/1024.0 as [TotalMB],(UsedExtents*64)/1024.0 as [UsedMB]

from #data

union all

select 'LOG',db_name()+' LOG',LogSize,((LogUsed/100)*LogSize) from #log where dbname = db_name()

--order by [Type],[Name]

)a

order by [Type],[Name]

drop table #data

drop table #log

|||

This will work for you:

-- Individual File Size query

SELECT name AS 'File Name' , physical_name AS 'Physical Name', size/128 AS 'Total Size in MB',

size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0 AS 'Available Space In MB', *

FROM sys.database_files;

Wednesday, March 21, 2012

Database error

Dear All,

i am getting this error messages relzated to "sp_configure"

can anyone please give me a solution for this

Critical --X-- 6:27:37 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3234 DBSPI40-1: Unable to fetch data from table 'sysdatabases' [Attempt to fetch on unopened cursor. (19525)].

Critical --X-- 6:27:36 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3233 DBSPI40-1: Unable to fetch data from table 'sysdatabases' [Attempt to fetch on unopened cursor. (19525)].

Critical 1 --X--X- 4:41:38 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3025 DBSPI40-1: Unable to fetch data from table 'spt_monitor' [Attempt to fetch on unopened cursor. (19525)].

Critical 4 --X--X- 3:44:43 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3227 DBSPI40-1: Unable to fetch data from table 'sysprocesses' [Attempt to fetch on unopened cursor. (19525)].

Critical 3 --X--X- 3:44:43 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3025 DBSPI40-1: Unable to fetch data from table 'sp_configure 'max degree of parallelism'' [Attempt to fetch on unopened cursor. (19525)].



Thanks & Regards

ferozWhere are you seeing these error messages? in the Windows Event Log?sql

Thursday, March 8, 2012

Database diagram to SQL tables

Dear Ng,
I have a Visio database diagram. How can I generate my tables from there to
the SQL server?
Many thanks and best regards,
Patrick
For Visio 2003 - Tools - Export Database and follow the wizard steps.
Cristian Lefter, SQL Server MVP
"Patrick" <Patrick@.discussions.microsoft.com> wrote in message
news:676A3402-4EB8-483E-97BA-CFC6A6C4A98E@.microsoft.com...
> Dear Ng,
> I have a Visio database diagram. How can I generate my tables from there
> to
> the SQL server?
> Many thanks and best regards,
> Patrick

Sunday, February 19, 2012

Database Design

Dear All,
I have just visited a colleague who advised me that the best way to design a
database (speed maximisation for end user be it web or vb) is not to have one
large database but to have your data split into 4 databases where the 4
divisions data is stored separately, rather than one larger database that
stores all data that has to be queried through Stored Procedures. The
databases are likely to be stored on the same hard disk so I don't think
there is a Serial I/O benefit to be gained.
These are not going to be large databases (only about 20,000 records). I
just don't know if my colleague is correct. The logic seems correct but where
is the evidence?
Thanks again.
Alastair MacFarlane
Hi Alastair,
You would get more benifits from ensuring you have the required indexes and
constraints in the database model then partioning the database.
The biggest benifit any databse can get is indexes and correct design. From
there and only after should you think about partionaing.
So while partionaing of Very large databases is good , first do the normal
stuff and then worry about it.
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Alastair MacFarlane" <AlastairMacFarlane@.discussions.microsoft.com> wrote
in message news:D9B3A0AD-A0EB-4066-A91A-80B9BD0FA4AB@.microsoft.com...
> Dear All,
> I have just visited a colleague who advised me that the best way to design
> a
> database (speed maximisation for end user be it web or vb) is not to have
> one
> large database but to have your data split into 4 databases where the 4
> divisions data is stored separately, rather than one larger database that
> stores all data that has to be queried through Stored Procedures. The
> databases are likely to be stored on the same hard disk so I don't think
> there is a Serial I/O benefit to be gained.
> These are not going to be large databases (only about 20,000 records). I
> just don't know if my colleague is correct. The logic seems correct but
> where
> is the evidence?
> Thanks again.
> Alastair MacFarlane

Database Design

Dear All,
I have just visited a colleague who advised me that the best way to design a
database (speed maximisation for end user be it web or vb) is not to have on
e
large database but to have your data split into 4 databases where the 4
divisions data is stored separately, rather than one larger database that
stores all data that has to be queried through Stored Procedures. The
databases are likely to be stored on the same hard disk so I don't think
there is a Serial I/O benefit to be gained.
These are not going to be large databases (only about 20,000 records). I
just don't know if my colleague is correct. The logic seems correct but wher
e
is the evidence?
Thanks again.
Alastair MacFarlaneHi Alastair,
You would get more benifits from ensuring you have the required indexes and
constraints in the database model then partioning the database.
The biggest benifit any databse can get is indexes and correct design. From
there and only after should you think about partionaing.
So while partionaing of Very large databases is good , first do the normal
stuff and then worry about it.
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Alastair MacFarlane" <AlastairMacFarlane@.discussions.microsoft.com> wrote
in message news:D9B3A0AD-A0EB-4066-A91A-80B9BD0FA4AB@.microsoft.com...
> Dear All,
> I have just visited a colleague who advised me that the best way to design
> a
> database (speed maximisation for end user be it web or vb) is not to have
> one
> large database but to have your data split into 4 databases where the 4
> divisions data is stored separately, rather than one larger database that
> stores all data that has to be queried through Stored Procedures. The
> databases are likely to be stored on the same hard disk so I don't think
> there is a Serial I/O benefit to be gained.
> These are not going to be large databases (only about 20,000 records). I
> just don't know if my colleague is correct. The logic seems correct but
> where
> is the evidence?
> Thanks again.
> Alastair MacFarlane

Database Design

Dear All,
I have just visited a colleague who advised me that the best way to design a
database (speed maximisation for end user be it web or vb) is not to have one
large database but to have your data split into 4 databases where the 4
divisions data is stored separately, rather than one larger database that
stores all data that has to be queried through Stored Procedures. The
databases are likely to be stored on the same hard disk so I don't think
there is a Serial I/O benefit to be gained.
These are not going to be large databases (only about 20,000 records). I
just don't know if my colleague is correct. The logic seems correct but where
is the evidence?
Thanks again.
Alastair MacFarlaneHi Alastair,
You would get more benifits from ensuring you have the required indexes and
constraints in the database model then partioning the database.
The biggest benifit any databse can get is indexes and correct design. From
there and only after should you think about partionaing.
So while partionaing of Very large databases is good , first do the normal
stuff and then worry about it.
kind regards
Greg O
Need to document your databases. Use the first and still the best AGS SQL
Scribe
http://www.ag-software.com
"Alastair MacFarlane" <AlastairMacFarlane@.discussions.microsoft.com> wrote
in message news:D9B3A0AD-A0EB-4066-A91A-80B9BD0FA4AB@.microsoft.com...
> Dear All,
> I have just visited a colleague who advised me that the best way to design
> a
> database (speed maximisation for end user be it web or vb) is not to have
> one
> large database but to have your data split into 4 databases where the 4
> divisions data is stored separately, rather than one larger database that
> stores all data that has to be queried through Stored Procedures. The
> databases are likely to be stored on the same hard disk so I don't think
> there is a Serial I/O benefit to be gained.
> These are not going to be large databases (only about 20,000 records). I
> just don't know if my colleague is correct. The logic seems correct but
> where
> is the evidence?
> Thanks again.
> Alastair MacFarlane

Friday, February 17, 2012

Database data file does not auto-grow

Dear all,
We are using SQL2000 sp4 on Windows 2000 Svr.
We found one of the database size become zero in Enterprise manager.
We have checked the database setting and the database is already set
auto-growth, without limit, by 1000Mb each time.
The data file size reach 6G now.
Is there anything we miss? That's the first time we meet this case.
We have checked the Harddisk drive for the data file and it still have over
100G space.
IvanIvan wrote:
> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have over
> 100G space.
> Ivan
Do you get an error message saying the filegroup is full?
What is the output of EXEC sp_spaceused?
Auto-growth is usually a bad idea and isn't something I would normally
recommend for a production application. Why would you want to grow a
6GB database in 1GB increments?
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||dbcc updateusage?
Cheers,
"Ivan" wrote:
> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have over
> 100G space.
> Ivan
>
>

Database data file does not auto-grow

Dear all,
We are using SQL2000 sp4 on Windows 2000 Svr.
We found one of the database size become zero in Enterprise manager.
We have checked the database setting and the database is already set
auto-growth, without limit, by 1000Mb each time.
The data file size reach 6G now.
Is there anything we miss? That's the first time we meet this case.
We have checked the Harddisk drive for the data file and it still have over
100G space.
Ivan
Ivan wrote:
> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have over
> 100G space.
> Ivan
Do you get an error message saying the filegroup is full?
What is the output of EXEC sp_spaceused?
Auto-growth is usually a bad idea and isn't something I would normally
recommend for a production application. Why would you want to grow a
6GB database in 1GB increments?
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
|||dbcc updateusage?
Cheers,
"Ivan" wrote:

> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have over
> 100G space.
> Ivan
>
>

Database data file does not auto-grow

Dear all,
We are using SQL2000 sp4 on Windows 2000 Svr.
We found one of the database size become zero in Enterprise manager.
We have checked the database setting and the database is already set
auto-growth, without limit, by 1000Mb each time.
The data file size reach 6G now.
Is there anything we miss? That's the first time we meet this case.
We have checked the Harddisk drive for the data file and it still have over
100G space.
IvanIvan wrote:
> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have ove
r
> 100G space.
> Ivan
Do you get an error message saying the filegroup is full?
What is the output of EXEC sp_spaceused?
Auto-growth is usually a bad idea and isn't something I would normally
recommend for a production application. Why would you want to grow a
6GB database in 1GB increments?
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||dbcc updateusage?
Cheers,
"Ivan" wrote:

> Dear all,
> We are using SQL2000 sp4 on Windows 2000 Svr.
> We found one of the database size become zero in Enterprise manager.
> We have checked the database setting and the database is already set
> auto-growth, without limit, by 1000Mb each time.
> The data file size reach 6G now.
> Is there anything we miss? That's the first time we meet this case.
> We have checked the Harddisk drive for the data file and it still have ove
r
> 100G space.
> Ivan
>
>