Showing posts with label disk. Show all posts
Showing posts with label disk. Show all posts

Wednesday, March 21, 2012

From Sql Column to file, OPENROWSET?

Hi There

I am using OPENROWSET to import a file from disk to a varbinary(max) column in sql server.

However as far as i can see OPENROWSET is only to import into Sql Server. However i need to reverse this as well, by that i mean export a varbinary(max) column data to a file on disk. How can i do this ? (The file is a compress text file).

How does this work for file types, i mean you can import any file as binary but when you export it back to disk will the file typr still work, will a .xls or a.exe imprted and exported like this still function 100%.

Thanx?

OPENROWSET

Includes all connection information necessary to access remote data from an OLE DB data source. This method is an alternative to accessing tables in a linked server and is a one-time, ad hoc method of connecting and accessing remote data using OLE DB. The OPENROWSET function can be referenced in the FROM clause of a query as though it is a table name. The OPENROWSET function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENROWSET returns only the first one.

you can use it with insert or update.

if you are handling blobs however like images, pdfs,docs etc. i recommend streaming it out to a file using ado or ado.net

here are some usefull links:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q258038

http://support.microsoft.com/kb/308042/EN-US/

|||

Hi joeydj

I would really like to stay away from .net, my last option would be to write a clr stored proc to output the file from the database, are you 100% this cannot be dine in TSQL? What about TEXTCOPY? This seems to only work for Text and image data. However somethig like this is what i am looking for.

Also it is not documented in BOL obviously this makes me nervous as it may be depricated in future?

Thanx

|||

I stand corrected seems textcopy was only for Sql Server 6.5 and 7.

It just seems od to me that Sql Server would provide a feature to get data from disk into sql server but not vica versa?

|||

You could use DTS (in SQL2000) or SSIS (in sql2005) to import/export the data.

|||

Thanx for the feedback

Let me elaborate.

This is at a distributed site running SQL Express and only Sql express(No ssis avalable). There is a column in a table that is in a varbinary(max) format, this column was populated from a file using OPENROWSET at a central location and sent to to site via service broker, now i need to write this file back at the remote site from the varbinary(max) column?

Thanx

|||

As far as I know (and I might be wrong on this) the openrowset allows importation from file in order for us to have bulk inserts - it was not created as a primary mechanism to communicate with the file system.

In your situation I would go with CLR . SQL Server 2005 ships with a sample of a CLR SP that shows how to do it (check on <<your sql server installation directory>>\90\Samples\Engine\Programmability\CLR\HandlingLOBUsingCLR) so you wouldn't have to code much...

|||

Thanx Miguel

Yes i am sure OPENROWSET was not made for that , just thought there was a function or something i did not know about.

Thanx i will check out the sample, just out of interest if everyone has reccomended CLR then i am guessing there is no way to do this in SS2000?

Thanx

|||In SQL2000 I would recommend DTS's.

Wednesday, March 7, 2012

Freeing Space after Deleting Rows

I deleted some records that contain blob data from a table
but realized no effect to my physical disk space.
Shrinking the table and/or database returned no positive
impact. executed sp_spaceused on the table with no effect.
Should I truncate the table to release the space?
Truncate will delete all records and that's not what is
expected.
Please give me your suggestions.
Thanks...
Stokowhat do you mean when you say 'physical disk space'? Are you talking about
OS level space at the file system level, or space reported by SQL as being
consumed by the table. Can you list exactly what output you're looking at?
It wasn't 100% clear to me from your message...
--
Brian
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:05cf01c3fadf$2111ede0$a401280a@.phx.gbl...
> I deleted some records that contain blob data from a table
> but realized no effect to my physical disk space.
> Shrinking the table and/or database returned no positive
> impact. executed sp_spaceused on the table with no effect.
> Should I truncate the table to release the space?
> Truncate will delete all records and that's not what is
> expected.
> Please give me your suggestions.
> Thanks...
> Stoko|||I am sorry for the lack of details.
I was expecting that after deleting a blob record holding
723556kb of file, this space should be released to the os
level of my server. hence if I had 2gigs of free space, I
should now have at least 2.7 gigs. This wasn't the case --
even at sql sever level, the space is still not released.
I appreciate your immediate response.
Stoko
>--Original Message--
>what do you mean when you say 'physical disk space'? Are
you talking about
>OS level space at the file system level, or space
reported by SQL as being
>consumed by the table. Can you list exactly what output
you're looking at?
>It wasn't 100% clear to me from your message...
>--
>Brian
>
>"stoko" <anonymous@.discussions.microsoft.com> wrote in
message
>news:05cf01c3fadf$2111ede0$a401280a@.phx.gbl...
>> I deleted some records that contain blob data from a
table
>> but realized no effect to my physical disk space.
>> Shrinking the table and/or database returned no positive
>> impact. executed sp_spaceused on the table with no
effect.
>> Should I truncate the table to release the space?
>> Truncate will delete all records and that's not what is
>> expected.
>> Please give me your suggestions.
>> Thanks...
>> Stoko
>
>.
>|||take a look at dbcc shrinkfile.
Files are not shrunk as space is remove from them. This is by design since
it would create a huge performance problem...
--
Brian Moran
Principal Mentor
Solid Quality Learning
SQL Server MVP
http://www.solidqualitylearning.com
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:079801c3fae2$f1c7ec70$a101280a@.phx.gbl...
> I am sorry for the lack of details.
> I was expecting that after deleting a blob record holding
> 723556kb of file, this space should be released to the os
> level of my server. hence if I had 2gigs of free space, I
> should now have at least 2.7 gigs. This wasn't the case --
> even at sql sever level, the space is still not released.
> I appreciate your immediate response.
> Stoko
> >--Original Message--
> >what do you mean when you say 'physical disk space'? Are
> you talking about
> >OS level space at the file system level, or space
> reported by SQL as being
> >consumed by the table. Can you list exactly what output
> you're looking at?
> >It wasn't 100% clear to me from your message...
> >
> >--
> >
> >Brian
> >
> >
> >"stoko" <anonymous@.discussions.microsoft.com> wrote in
> message
> >news:05cf01c3fadf$2111ede0$a401280a@.phx.gbl...
> >> I deleted some records that contain blob data from a
> table
> >> but realized no effect to my physical disk space.
> >> Shrinking the table and/or database returned no positive
> >> impact. executed sp_spaceused on the table with no
> effect.
> >>
> >> Should I truncate the table to release the space?
> >> Truncate will delete all records and that's not what is
> >> expected.
> >>
> >> Please give me your suggestions.
> >> Thanks...
> >> Stoko
> >
> >
> >.
> >

Freeing space after deleting records.

I deleted some records that contain blob data from a
table but realized no effect to my physical disk space.
Shrinking the table and/or database returned no positive
impact. executed sp_spaceused on the table with no
effect.
Should I truncate the table to release the space? Truncate
will delete all records and that's not what is
expected.
I was expecting that after deleting the blob record
holding 723556kb of file, this space should be released to
the os level of my server. hence if I had 2gigs of free
space, I should now have at least 2.7 gigs. This wasn't
the case -- even at sql sever level, the space is still
not released.
I appreciate your immediate response.
StokoCheck back in the archives, a few weeks. There was some discussion about the
same topic and if my memory serves me, to free space for blobs, you need to
re.load the table. I'm not sure about the details, so, I suggest you check
the archives to make sure.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:077501c3faf2$b2fdc130$a501280a@.phx.gbl...
> I deleted some records that contain blob data from a
> table but realized no effect to my physical disk space.
> Shrinking the table and/or database returned no positive
> impact. executed sp_spaceused on the table with no
> effect.
> Should I truncate the table to release the space? Truncate
> will delete all records and that's not what is
> expected.
> I was expecting that after deleting the blob record
> holding 723556kb of file, this space should be released to
> the os level of my server. hence if I had 2gigs of free
> space, I should now have at least 2.7 gigs. This wasn't
> the case -- even at sql sever level, the space is still
> not released.
> I appreciate your immediate response.
> Stoko
>|||Hi,
Execute the below commands
sp_spaceused table_name,@.updateusage ='TRUE'
go
Update statistics table_name
After this check the space utilized by the table and then use DBCC
SHRINKFILE to shrink the physical file.
Thanks
Hari
MCDBA
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:077501c3faf2$b2fdc130$a501280a@.phx.gbl...
> I deleted some records that contain blob data from a
> table but realized no effect to my physical disk space.
> Shrinking the table and/or database returned no positive
> impact. executed sp_spaceused on the table with no
> effect.
> Should I truncate the table to release the space? Truncate
> will delete all records and that's not what is
> expected.
> I was expecting that after deleting the blob record
> holding 723556kb of file, this space should be released to
> the os level of my server. hence if I had 2gigs of free
> space, I should now have at least 2.7 gigs. This wasn't
> the case -- even at sql sever level, the space is still
> not released.
> I appreciate your immediate response.
> Stoko
>

Freeing space after deleting records.

I deleted some records that contain blob data from a
table but realized no effect to my physical disk space.
Shrinking the table and/or database returned no positive
impact. executed sp_spaceused on the table with no
effect.
Should I truncate the table to release the space? Truncate
will delete all records and that's not what is
expected.
I was expecting that after deleting the blob record
holding 723556kb of file, this space should be released to
the os level of my server. hence if I had 2gigs of free
space, I should now have at least 2.7 gigs. This wasn't
the case -- even at sql sever level, the space is still
not released.
I appreciate your immediate response.
StokoCheck back in the archives, a few weeks. There was some discussion about the
same topic and if my memory serves me, to free space for blobs, you need to
re.load the table. I'm not sure about the details, so, I suggest you check
the archives to make sure.
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:077501c3faf2$b2fdc130$a501280a@.phx.gbl...
> I deleted some records that contain blob data from a
> table but realized no effect to my physical disk space.
> Shrinking the table and/or database returned no positive
> impact. executed sp_spaceused on the table with no
> effect.
> Should I truncate the table to release the space? Truncate
> will delete all records and that's not what is
> expected.
> I was expecting that after deleting the blob record
> holding 723556kb of file, this space should be released to
> the os level of my server. hence if I had 2gigs of free
> space, I should now have at least 2.7 gigs. This wasn't
> the case -- even at sql sever level, the space is still
> not released.
> I appreciate your immediate response.
> Stoko
>|||Hi,
Execute the below commands
sp_spaceused table_name,@.updateusage ='TRUE'
go
Update statistics table_name
After this check the space utilized by the table and then use DBCC
SHRINKFILE to shrink the physical file.
Thanks
Hari
MCDBA
"stoko" <anonymous@.discussions.microsoft.com> wrote in message
news:077501c3faf2$b2fdc130$a501280a@.phx.gbl...
> I deleted some records that contain blob data from a
> table but realized no effect to my physical disk space.
> Shrinking the table and/or database returned no positive
> impact. executed sp_spaceused on the table with no
> effect.
> Should I truncate the table to release the space? Truncate
> will delete all records and that's not what is
> expected.
> I was expecting that after deleting the blob record
> holding 723556kb of file, this space should be released to
> the os level of my server. hence if I had 2gigs of free
> space, I should now have at least 2.7 gigs. This wasn't
> the case -- even at sql sever level, the space is still
> not released.
> I appreciate your immediate response.
> Stoko
>

Sunday, February 26, 2012

Free Space Alert in Sql Server

Hi,
Is there any way I can get alert message from sql server if one of local
hard disk drive goes out of space or less than 500 mb.
Thanks,
San
I wrote a job that wakes up every hour, uses master..xp_fixeddrives to poll
the local disks, and sends an alert if any are getting low.
Run this and you should get a quick idea:
EXEC master..xp_fixeddrives
http://www.aspfaq.com/
(Reverse address to reply.)
"San" <San@.discussions.microsoft.com> wrote in message
news:D4D16EAE-50E8-409F-9172-DD715F0D0B9D@.microsoft.com...
> Hi,
> Is there any way I can get alert message from sql server if one of local
> hard disk drive goes out of space or less than 500 mb.
> Thanks,
> San

Friday, February 24, 2012

Free disk space in a cluster

Hi,

is there a way to restrict the result of xp_fixeddrives only to those drives the SQL Server cluster group has a dependency on? Or, to say more generally, how can one find out the free disk space available for remote clustered SQL Server using only TSQL?

Thanks a lot.

try:

select * from fn_servershareddrives()

or

select * from sys.dm_io_cluser_shared_drives

Sunday, February 19, 2012

Fragmented Disk causing deadlock?

Hi,
I was hoping someone may be able to shed some light on a deadlocking issue w
hich I feel may be due to fragmentation.
Server Spec:
win2k sp4
sql server 2000 sp3
2 G RAM
1600 M allocated to SQL Server
12 G Disk Drive
4 G Database Size
5 G Free on Disk Drive
80 concurrent users, approximately half are connecting through odbc while ha
lf are connecting using jdbc.
I encounter a deadlock where an odbc user is trying to select a particular t
able while a jdbc user is trying to delete from the same table. The affecte
d table has 1.2 million rows. The delete command from the jdbc involves 1 in
dexed row while the select
command from the odbc involves approximately 50 indexed rows.
The issue has only recently appeared after 2 years of running the same odbc/
jdbc applications.
I have tried running the sql statements on separate Query Analyzers to repli
cate the deadlocking issue but this does not reproduce it.
I have rebuilt all indexes, updated statistics, rebooted Server, installed l
atest jdbc driver but no joy.
Recently I have had to shrink the datafile to free up much needed disk space
. There is fragmentation on the data disk, there is one datafile which holds
the database which is fragmented into 5 segments.
The Extent Scan Fragmentation on the database table is 31%.
Has any one else encountered a similar issue with deadlocks occurring due to
a fragmented disk and or fragmented datafile?
Any suggestions are appreciated.Hi Michael
Fragmentation *can* contribute to deadlocking if it lengthens transaction
times by delaying resource acquisition times. Basically, anything that makes
queries run slower can make transaction times longer & therefore increasing
deadlock susceptibility.
I'm surprised that your scan fragmentation is 31% given you said that you've
re-indexed. Does that table have a clustered index?
When you want to trouble-shoot a deadlock, it's important to get a solid
grasp as to exactly what resources are contributing to it. To do this, you
issue the command dbcc traceon (1204, 3605, -1) which causes sql server to
write detailed deadlock information into the error log. When a deadlock
occurs you can then go to the error log and see exactly what resources
(tables, rows, indexes etc) are being deadlocked by what statements.
It would be very useful to get that output to help you further here.
Regards,
Greg Linwood
SQL Server MVP
"Michael" <anonymous@.discussions.microsoft.com> wrote in message
news:684A2202-4242-4F5F-A27F-5E820108A21F@.microsoft.com...
> Hi,
> I was hoping someone may be able to shed some light on a deadlocking issue
which I feel may be due to fragmentation.
> Server Spec:
> win2k sp4
> sql server 2000 sp3
> 2 G RAM
> 1600 M allocated to SQL Server
> 12 G Disk Drive
> 4 G Database Size
> 5 G Free on Disk Drive
>
> 80 concurrent users, approximately half are connecting through odbc while
half are connecting using jdbc.
> I encounter a deadlock where an odbc user is trying to select a particular
table while a jdbc user is trying to delete from the same table. The
affected table has 1.2 million rows. The delete command from the jdbc
involves 1 indexed row while the select command from the odbc involves
approximately 50 indexed rows.
> The issue has only recently appeared after 2 years of running the same
odbc/jdbc applications.
> I have tried running the sql statements on separate Query Analyzers to
replicate the deadlocking issue but this does not reproduce it.
> I have rebuilt all indexes, updated statistics, rebooted Server, installed
latest jdbc driver but no joy.
> Recently I have had to shrink the datafile to free up much needed disk
space. There is fragmentation on the data disk, there is one datafile which
holds the database which is fragmented into 5 segments.
> The Extent Scan Fragmentation on the database table is 31%.
> Has any one else encountered a similar issue with deadlocks occurring due
to a fragmented disk and or fragmented datafile?
> Any suggestions are appreciated.
>