Showing posts with label below. Show all posts
Showing posts with label below. Show all posts

Thursday, March 29, 2012

Alternate to a not in query

-- tested schema below --
-- create tables --
create table tbl_test
(serialnumber char(12))
go
create table tbl_test2
(serialnumber char(12),
exportedflag int)
go
--insert data --
insert into tbl_test2 values ('123456789010',0)
insert into tbl_test2 values ('123456789011',0)
insert into tbl_test2 values ('123456789012',0)
insert into tbl_test2 values ('123456789013',0)
insert into tbl_test2 values ('123456789014',0)
insert into tbl_test2 values ('123456789015',0)
insert into tbl_test2 values ('123456789016',0)
insert into tbl_test2 values ('123456789017',0)
insert into tbl_test2 values ('123456789018',0)
insert into tbl_test2 values ('123456789019',0)

insert into tbl_test values ('123456789011')
insert into tbl_test values ('123456789012')
insert into tbl_test values ('123456789013')
insert into tbl_test values ('123456789014')
insert into tbl_test values ('123456789015')

-- query --
Select serialnumber from tbl_test2
where serialnumber
not in (select serialnumber from tbl_test) and
exportedflag=0

This query runs quite fast with only the data above but when both
tables get million plus rows, the query simply bogs down. Is there a
better way to write this query?Select serialnumber
from tbl_test2 a
left joint tbl_test b on a. serialnumber = b.serialnumber
where (b.serialnumber IS NULL)
AND (a.exportedflag=0)|||There is another way to write the query, but it's not better (in fact,
I think it's worse):

Select tbl_test2.serialnumber from tbl_test2
left join tbl_test on tbl_test2.serialnumber=tbl_test.serialnumber
where exportedflag=0 and tbl_test.serialnumber is null

To improve the performance of this query, you should create primary
keys on the tables. Besides the conceptual benefits of a proper design,
this would accomplish (at least) the following things:
- create an index on the serialnumber column
- declare that the serialnumber column does not allow duplicates
- declare that the serialnumber column does not allow nulls
These things will help the Query Optimizer very much to create a better
execution plan.

Razvan|||
Razvan Socol wrote:
> There is another way to write the query, but it's not better (in fact,
> I think it's worse):
> Select tbl_test2.serialnumber from tbl_test2
> left join tbl_test on tbl_test2.serialnumber=tbl_test.serialnumber
> where exportedflag=0 and tbl_test.serialnumber is null

Razvan,

Why worse?

The common wisdom seems to be that it is always more efficient
eliminate nested subqueries, if possible.

My understanding is that the optimizer will internally eliminate the
subquery by doing a left join as above if it can.|||Ira Gladnick (IraGladnick@.yahoo.com) writes:
> Why worse?
> The common wisdom seems to be that it is always more efficient
> eliminate nested subqueries, if possible.

It's worse, becase it does not express the intent of the query equally
well, and therefore can contribute to higher maintenance costs.

> My understanding is that the optimizer will internally eliminate the
> subquery by doing a left join as above if it can.

I don't know if this is the case, but in such case there is even less
reason to rewrite the query in an obscure way.

I would write the query as:

Select serialnumber
from tbl_test2 t2
where not exists (select *
from tbl_test t
where t2.serialnuber = t.serialnumber)
and exportedflag=0

In SQL 6.5 this would typically perform better than NOT IN. But I believe
SQL 2000 will rewrite NOT IN to NOT EXISTS internally, so it is not that
much of an issue for performance. But NOT EXISTS is more general to use
than NOT IN, because you can handle multi-column conditions. Furthermore,
if there are NULL values involved, NOT IN can give you surpriese.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||(kjaggi@.hotmail.com) writes:
> -- query --
> Select serialnumber from tbl_test2
> where serialnumber
> not in (select serialnumber from tbl_test) and
> exportedflag=0
> This query runs quite fast with only the data above but when both
> tables get million plus rows, the query simply bogs down. Is there a
> better way to write this query?

Beside the obvious point from Razvan about indexes, if you are on a multi-
CPU box, you can try this at the end of the query:

OPTION (MAXDOP 1)

this turns off parallelism. I've seen SQL Server use massive parallel
plans for this type of query, when a non-parallel plan have been much
faster.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

Alternate of Scalar Function for Comma Sepated Selection

I have 2 Tables as below,

1) Purchase_Invoice

a. PurchaseInvoiceID

b. SupplierName

c. BillNo

d. BillDate

2) Purchase_Invoice_Items

a. PurchaseInvoiceItemID

b. PurhcaseInvoiceID (FK to Purchase_Invoice Table)

c. ItemName

d. Quantity

e. Rate

Now I want to select all the records of Purhcase_Invoice table exactly once with one column at last containing comma separated Item name of particular PurhcaseInvoiceID as below

PurchaseInvoiceID|SupplierName | BillNo | BillDate | Items (Comma Separated Items)

Currently I am using Scalar Function which takes PurchaseInvoiceID as Argument and Returns Comma Separated Itemnames…

It works well but when number of records are large than performance is very poor.

Is there another way of doing same thing? By Join or By some System Function?

Nilesh

If you're using SQL2005, i'd use a CLR table valued funciton that would join the 2 tables and then format the results as you require.

While i've not done this myself i would guess that querying the data once and then manipulating the resultset would be your quickest solution.

HTH!

Tuesday, March 27, 2012

altering table with default value

Hi, How to alter a table with default value?
I am using the below statement, But, it is not working..Any pointers?
Thx..
----------
alter table action_item ALTER COLUMN STATUS default 0ALTER TABLE ACTION_ITEM ADD CONSTRAINT
DF_ACTION_ITEM_STATUS DEFAULT 0 FOR STATUS
GO
UPDATE ACTION_ITEM SET STATUS =0 where STATUS IS NULL
GO

Tuesday, March 20, 2012

Alter Table in Stored Procedure

Hi,
The script in the stored procedure below works. But, when creating the
stored procedure, I only see the first 'if'. There is nothing in there.
I tried through Enterprise Manager as well. Anybody knows what could be
causing this?
Thanks,
CREATE PROCEDURE sp_ImportKEYBANKAccountsFeed
AS
-- Drop Constraints
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_tblAccounts_tblAccountTypes]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccounts] DROP CONSTRAINT
[FK_tblAccounts_tblAccountTypes]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo]. [FK_tblAccTransactions_tblTransactionTyp
es]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccTransactions] DROP CONSTRAINT
[FK_tblAccTransactions_tblTransactionTyp
es]
GO
-- Clean tables
TRUNCATE TABLE [dbo].[tblAccounts]
GO
TRUNCATE TABLE [dbo].[tblAccountTypes]
GO
TRUNCATE TABLE [dbo].[tblAccTransactions]
GO
TRUNCATE TABLE [dbo].[tblTransactionTypes]
GO
-- Populate tables
INSERT INTO tblAccountTypes
(
AccountTypeID,
TypeDesc
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractAccountTypes
GO
INSERT INTO tblTransactionTypes
(
TransactionTypeID,
TransactionDesc
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractTranCodes
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractESBAccounts
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractSavingsAccounts
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractPLAccounts
GO
INSERT INTO tblAccTransactions
(
KeyBankTransID,
KeyBankCustomerID,
AccountID,
TransactionTypeID,
Reference,
Debit,
Credit,
Balance,
Arrears,
BookingDate,
Amount,
Narrative
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractTrans
GO
--Add Constraints back to tables
if not exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_tblAccounts_tblAccountTypes]') and
OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccounts] ADD CONSTRAINT
[FK_tblAccounts_tblAccountTypes]
FOREIGN KEY ([AccountTypeID]) REFERENCES [tblAccountTypes]
([AccountTypeID])
GO
if not exists (select * from dbo.sysobjects where id =
object_id(N'[dbo]. [FK_tblAccTransactions_tblTransactionTyp
es]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccTransactions] ADD CONSTRAINT
[FK_tblAccTransactions_tblTransactionTyp
es]
FOREIGN KEY([TransactionTypeID] ) REFERENCES [tblTransactionTypes]
([TransactionTypeID])
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
*** Sent via Developersdex http://www.examnotes.net ***That's because GO is a batch terminator
If you do sp_helptext 'ImportKEYBANKAccountsFeed ' you will see that
the procedure stops after the first GO
Take out the GO's
Denis the SQL Menace
http://sqlservercode.blogspot.com/

Sunday, March 11, 2012

ALTER SESSION query ?

Hi,
What is the equivalent for below Oracle's ALTER SESSION query :
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:mi:ss'
Thanks,
SamActually I don't think there is one. SET DATEFORMAT has no affect on the way datetime or smalldatetime values are displayed.

Friday, February 24, 2012

already ran aspnet_regsql but "Could not establish a connection to the database. "

i already ran aspnet_regsql but i still get below...anyone know why? thanks in advance

Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.

Check whether SQL Server 2005 Express is running.

Jos

|||

Hi, Firstly ensure that you have completed aspnet_regsql properly by running through and check that the tables are there by using a application such as SQL server management tool.

Then ensure that the web.config file has the correct connection string for your website.

Any problems just post back here.

Dan

|||

yes..i only had sql 2000 installed.

thanks

|||

It has happened to the bestWink

Jos

Sunday, February 19, 2012

ALLOW_DUP_ROW is no longer supported

Any body please give me the details about how to use 'ALLOW_DUP_ROW' in a CREATE CLUSTERED INDEX statement.

I tried executing the below statement but it throws an error "CREATE INDEX option 'ALLOW_DUP_ROW' is no longer supported."(both in SQL Server 2000 and SQL Server 2005)

CREATE CLUSTERED INDEX index121
ON raj(j)
WITH ALLOW_DUP_ROW

raj(j) contains two rows with same value

please hhelp me outneed a quick help ,|||Clustered indexes allow duplicate rows by default. You have to create it as a primary key or add a unique constraint in order to prevent duplicate rows.

Monday, February 13, 2012

allocated, unused and free space

Considering the output of sp_spaceused (below) on my SQL Server 2005
database, is it possible to get back (release to the OS) the UNUSED space,
shrinking does not do it.
Basically I need to resize this database, most of its space is not being
used and is filling up my backup storage.
I have plenty of room in my data drive but I keep serveral days worth of
backups and thouse GB start to add up and fill up my backup drive.
Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
database_name: c8audit
database_size: 26960.63 MB
unallocated space: 2033.20 MB
reserved: 25521840 KB
data: 3561528 KB
index_size: 8440 KB
unused: 21951872 KB
Thanks,
Tim
DBCC SHRINKFILE will return the space to the OS as long as it is able to
shrink it in the first place. Can you try running that command and post the
actual command you used with all the parameters along with the output from
it? The backups do not include "free space" and only backup the actual
data. So if you have 4GB of data your backups should be roughly 4GB
regardless of how large your db is overall.
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
> Considering the output of sp_spaceused (below) on my SQL Server 2005
> database, is it possible to get back (release to the OS) the UNUSED space,
> shrinking does not do it.
> Basically I need to resize this database, most of its space is not being
> used and is filling up my backup storage.
> I have plenty of room in my data drive but I keep serveral days worth of
> backups and thouse GB start to add up and fill up my backup drive.
> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
> database_name: c8audit
> database_size: 26960.63 MB
> unallocated space: 2033.20 MB
> reserved: 25521840 KB
> data: 3561528 KB
> index_size: 8440 KB
> unused: 21951872 KB
> Thanks,
> Tim
>
|||Hi Tim
There is a difference between allocated and unused space. Unallocated space
could be returned to the OS when you shrink a file, but the unused space is
space that has already been allocated to an object, but just doesn't yet
have any data stored in it.
Without seeing you table definitions and knowing the kind of data you're
storing, it's hard to know why you have so much unused space in your tables.
You might try running sp_spaceused on each table, and see which ones have
the most unused.
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
> Considering the output of sp_spaceused (below) on my SQL Server 2005
> database, is it possible to get back (release to the OS) the UNUSED space,
> shrinking does not do it.
> Basically I need to resize this database, most of its space is not being
> used and is filling up my backup storage.
> I have plenty of room in my data drive but I keep serveral days worth of
> backups and thouse GB start to add up and fill up my backup drive.
> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
> database_name: c8audit
> database_size: 26960.63 MB
> unallocated space: 2033.20 MB
> reserved: 25521840 KB
> data: 3561528 KB
> index_size: 8440 KB
> unused: 21951872 KB
> Thanks,
> Tim
>
|||Thanks all for your help.
Using SQL Server 2005's standard report "Disk Usage by Table" I was able to
find out that about 90% of the unused space has been allocated to ONE table.
Among this table's fields there are two VARCHAR that caught my attention
because their lengths are bigger than normal, one is 1024 the other one is
2000.
The table has about 2 million records and both of these fields are only
storing a few characters, even though I have not done any calculations I
believe the free space is in these almost empty fields.
I can't modify the fields' length, but about 90% of the records on this
table can go, so I'm going to delete the records to regain the space.
I did this in TEST after my original post and it worked, the UNUSED space
became AVAILABLE FREE and shrinking released it.
Again THANKS!
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:eyBNF$ebIHA.4208@.TK2MSFTNGP04.phx.gbl...
> Hi Tim
> There is a difference between allocated and unused space. Unallocated
> space could be returned to the OS when you shrink a file, but the unused
> space is space that has already been allocated to an object, but just
> doesn't yet have any data stored in it.
> Without seeing you table definitions and knowing the kind of data you're
> storing, it's hard to know why you have so much unused space in your
> tables. You might try running sp_spaceused on each table, and see which
> ones have the most unused.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://blog.kalendelaney.com
>
> "Tim Bales" <timbales@.bellsouth.net> wrote in message
> news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
>
|||Hi Tim
I'm glad you were able to accomplish your goal.
However, it's a mystery what the cause of all the unused space was. A
varchar column should not reserve more space than it actually uses. So if
there were only a few characters in them, that should not have caused excess
space allocation. It might have been that there was padding with spaces, or
it might have been that the columns were longer originally and then updated.
But if you've deleted the rows, we'll probably never know. ;-)
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:%23SIRI7kbIHA.1376@.TK2MSFTNGP02.phx.gbl...
> Thanks all for your help.
> Using SQL Server 2005's standard report "Disk Usage by Table" I was able
> to find out that about 90% of the unused space has been allocated to ONE
> table.
> Among this table's fields there are two VARCHAR that caught my attention
> because their lengths are bigger than normal, one is 1024 the other one is
> 2000.
> The table has about 2 million records and both of these fields are only
> storing a few characters, even though I have not done any calculations I
> believe the free space is in these almost empty fields.
> I can't modify the fields' length, but about 90% of the records on this
> table can go, so I'm going to delete the records to regain the space.
> I did this in TEST after my original post and it worked, the UNUSED space
> became AVAILABLE FREE and shrinking released it.
> Again THANKS!
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:eyBNF$ebIHA.4208@.TK2MSFTNGP04.phx.gbl...
>

allocated, unused and free space

Considering the output of sp_spaceused (below) on my SQL Server 2005
database, is it possible to get back (release to the OS) the UNUSED space,
shrinking does not do it.
Basically I need to resize this database, most of its space is not being
used and is filling up my backup storage.
I have plenty of room in my data drive but I keep serveral days worth of
backups and thouse GB start to add up and fill up my backup drive.
Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
database_name: c8audit
database_size: 26960.63 MB
unallocated space: 2033.20 MB
reserved: 25521840 KB
data: 3561528 KB
index_size: 8440 KB
unused: 21951872 KB
Thanks,
TimDBCC SHRINKFILE will return the space to the OS as long as it is able to
shrink it in the first place. Can you try running that command and post the
actual command you used with all the parameters along with the output from
it? The backups do not include "free space" and only backup the actual
data. So if you have 4GB of data your backups should be roughly 4GB
regardless of how large your db is overall.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
> Considering the output of sp_spaceused (below) on my SQL Server 2005
> database, is it possible to get back (release to the OS) the UNUSED space,
> shrinking does not do it.
> Basically I need to resize this database, most of its space is not being
> used and is filling up my backup storage.
> I have plenty of room in my data drive but I keep serveral days worth of
> backups and thouse GB start to add up and fill up my backup drive.
> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
> database_name: c8audit
> database_size: 26960.63 MB
> unallocated space: 2033.20 MB
> reserved: 25521840 KB
> data: 3561528 KB
> index_size: 8440 KB
> unused: 21951872 KB
> Thanks,
> Tim
>|||Hi Tim
There is a difference between allocated and unused space. Unallocated space
could be returned to the OS when you shrink a file, but the unused space is
space that has already been allocated to an object, but just doesn't yet
have any data stored in it.
Without seeing you table definitions and knowing the kind of data you're
storing, it's hard to know why you have so much unused space in your tables.
You might try running sp_spaceused on each table, and see which ones have
the most unused.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
> Considering the output of sp_spaceused (below) on my SQL Server 2005
> database, is it possible to get back (release to the OS) the UNUSED space,
> shrinking does not do it.
> Basically I need to resize this database, most of its space is not being
> used and is filling up my backup storage.
> I have plenty of room in my data drive but I keep serveral days worth of
> backups and thouse GB start to add up and fill up my backup drive.
> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
> database_name: c8audit
> database_size: 26960.63 MB
> unallocated space: 2033.20 MB
> reserved: 25521840 KB
> data: 3561528 KB
> index_size: 8440 KB
> unused: 21951872 KB
> Thanks,
> Tim
>|||Thanks all for your help.
Using SQL Server 2005's standard report "Disk Usage by Table" I was able to
find out that about 90% of the unused space has been allocated to ONE table.
Among this table's fields there are two VARCHAR that caught my attention
because their lengths are bigger than normal, one is 1024 the other one is
2000.
The table has about 2 million records and both of these fields are only
storing a few characters, even though I have not done any calculations I
believe the free space is in these almost empty fields.
I can't modify the fields' length, but about 90% of the records on this
table can go, so I'm going to delete the records to regain the space.
I did this in TEST after my original post and it worked, the UNUSED space
became AVAILABLE FREE and shrinking released it.
Again THANKS!
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:eyBNF$ebIHA.4208@.TK2MSFTNGP04.phx.gbl...
> Hi Tim
> There is a difference between allocated and unused space. Unallocated
> space could be returned to the OS when you shrink a file, but the unused
> space is space that has already been allocated to an object, but just
> doesn't yet have any data stored in it.
> Without seeing you table definitions and knowing the kind of data you're
> storing, it's hard to know why you have so much unused space in your
> tables. You might try running sp_spaceused on each table, and see which
> ones have the most unused.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> http://blog.kalendelaney.com
>
> "Tim Bales" <timbales@.bellsouth.net> wrote in message
> news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
>> Considering the output of sp_spaceused (below) on my SQL Server 2005
>> database, is it possible to get back (release to the OS) the UNUSED
>> space, shrinking does not do it.
>> Basically I need to resize this database, most of its space is not being
>> used and is filling up my backup storage.
>> I have plenty of room in my data drive but I keep serveral days worth of
>> backups and thouse GB start to add up and fill up my backup drive.
>> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
>> database_name: c8audit
>> database_size: 26960.63 MB
>> unallocated space: 2033.20 MB
>> reserved: 25521840 KB
>> data: 3561528 KB
>> index_size: 8440 KB
>> unused: 21951872 KB
>> Thanks,
>> Tim
>|||Hi Tim
I'm glad you were able to accomplish your goal.
However, it's a mystery what the cause of all the unused space was. A
varchar column should not reserve more space than it actually uses. So if
there were only a few characters in them, that should not have caused excess
space allocation. It might have been that there was padding with spaces, or
it might have been that the columns were longer originally and then updated.
But if you've deleted the rows, we'll probably never know. ;-)
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://blog.kalendelaney.com
"Tim Bales" <timbales@.bellsouth.net> wrote in message
news:%23SIRI7kbIHA.1376@.TK2MSFTNGP02.phx.gbl...
> Thanks all for your help.
> Using SQL Server 2005's standard report "Disk Usage by Table" I was able
> to find out that about 90% of the unused space has been allocated to ONE
> table.
> Among this table's fields there are two VARCHAR that caught my attention
> because their lengths are bigger than normal, one is 1024 the other one is
> 2000.
> The table has about 2 million records and both of these fields are only
> storing a few characters, even though I have not done any calculations I
> believe the free space is in these almost empty fields.
> I can't modify the fields' length, but about 90% of the records on this
> table can go, so I'm going to delete the records to regain the space.
> I did this in TEST after my original post and it worked, the UNUSED space
> became AVAILABLE FREE and shrinking released it.
> Again THANKS!
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:eyBNF$ebIHA.4208@.TK2MSFTNGP04.phx.gbl...
>> Hi Tim
>> There is a difference between allocated and unused space. Unallocated
>> space could be returned to the OS when you shrink a file, but the unused
>> space is space that has already been allocated to an object, but just
>> doesn't yet have any data stored in it.
>> Without seeing you table definitions and knowing the kind of data you're
>> storing, it's hard to know why you have so much unused space in your
>> tables. You might try running sp_spaceused on each table, and see which
>> ones have the most unused.
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>> www.InsideSQLServer.com
>> http://blog.kalendelaney.com
>>
>> "Tim Bales" <timbales@.bellsouth.net> wrote in message
>> news:OXgzVobbIHA.4880@.TK2MSFTNGP03.phx.gbl...
>> Considering the output of sp_spaceused (below) on my SQL Server 2005
>> database, is it possible to get back (release to the OS) the UNUSED
>> space, shrinking does not do it.
>> Basically I need to resize this database, most of its space is not being
>> used and is filling up my backup storage.
>> I have plenty of room in my data drive but I keep serveral days worth of
>> backups and thouse GB start to add up and fill up my backup drive.
>> Of the 28 GB only about 4 GB are being used, the rest is just RESERVED.
>> database_name: c8audit
>> database_size: 26960.63 MB
>> unallocated space: 2033.20 MB
>> reserved: 25521840 KB
>> data: 3561528 KB
>> index_size: 8440 KB
>> unused: 21951872 KB
>> Thanks,
>> Tim
>>
>