473,473 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Example of binary data type in SQL Server

There are two datatypes for storing binary data type in the SQL Server:

1. binary - for fixed length binary data
2. varbinary - for variable length data

My question is: how is data inserted into them? Do they have any
delimiters that go into the insert statement like strings and datetimes
have? What format (hex/decimal?) do they accept data in? Can you please
give me an insert statement example?

Jan 29 '06 #1
9 34119
When we wrote the SQL Stanardards, we wanted to design a high level
abstract language for data that would be portable beause it would NEVER
deal with the low level PHYSICAL representation of the data.

Why do you wish to write kludges?

Jan 29 '06 #2

Water Cooler v2 wrote:
There are two datatypes for storing binary data type in the SQL Server:

1. binary - for fixed length binary data
2. varbinary - for variable length data

My question is: how is data inserted into them? Do they have any
delimiters that go into the insert statement like strings and datetimes
have? What format (hex/decimal?) do they accept data in? Can you please
give me an insert statement example?


Apparently Celko forgot about the part where you answer the question.

I've always done it by encoding it in hex first. Then you can do
something like this:

insert myTable (myBinaryColumn) values (0x8d7e6a5d4b3e2e1f)

Just put the 0x before whatever hex value you come up with. The
difference between the two is the same as the difference between char
and varchar. In general, if the values in that column are either short
or all roughly (or exactly) the same length, use binary. Otherwise,
use varbinary.

Jan 29 '06 #3
In addition to what ZeldorBlat said, if you need to make larger values, keep
in mind that the + operator is used to concatenate binary strings.

eg: 0xA34B + 0xCA02 is 0xA34BCA02

This can help break such strings up over multiple lines in a script.

HTH,

Greg

"Water Cooler v2" <wt*****@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
There are two datatypes for storing binary data type in the SQL Server:

1. binary - for fixed length binary data
2. varbinary - for variable length data

My question is: how is data inserted into them? Do they have any
delimiters that go into the insert statement like strings and datetimes
have? What format (hex/decimal?) do they accept data in? Can you please
give me an insert statement example?

Jan 29 '06 #4
--CELKO-- (jc*******@earthlink.net) writes:
When we wrote the SQL Stanardards, we wanted to design a high level
abstract language for data that would be portable beause it would NEVER
deal with the low level PHYSICAL representation of the data.


And what if the data is binary? How would you store a JPEG image in a
database? You would disassemble it, and store it in some high-level format?

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 29 '06 #5
>> How would you store a JPEG image in a database? You would disassemble it, and store it in some high-level format? <<

1) Store a file name as a string, so that the application can grab the
file.

2) If this is a serious problem, then use an image base tool. IBM has
one that lets you make a drawing as the query and it will pull out the
ones that are closest; there are several products that do nothign but
face and fingerprint matching; CAD systems that handle 3D objects; etc.
SQL is not the answer to everything.

Jan 30 '06 #6

--CELKO-- wrote:
How would you store a JPEG image in a database? You would disassemble it, and store it in some high-level format? <<


1) Store a file name as a string, so that the application can grab the
file.

2) If this is a serious problem, then use an image base tool. IBM has
one that lets you make a drawing as the query and it will pull out the
ones that are closest; there are several products that do nothign but
face and fingerprint matching; CAD systems that handle 3D objects; etc.
SQL is not the answer to everything.


Again, you still haven't answered the question.

Jan 30 '06 #7
Amazingly, I agree with Celko here. #1 is what we do and it works
really well. It allows you to have a separate file server when you need
greater storage space for user files without haveing to make your SQL
Server a file server.

Jan 30 '06 #8
--CELKO-- (jc*******@earthlink.net) writes:
How would you store a JPEG image in a database? You would disassemble
it, and store it in some high-level format? <<
1) Store a file name as a string, so that the application can grab the
file.
Yes, this is an option. Just as you could store employee names,
number of car doors or what ever on a file, and then store the file
name in the database.

However, it's difficult to get transactional consistency with a file
system. You commit the transaction, but the file could not be stored
on disk. Or the file is stored on disk, but then the transaction was
rolled back for some resaon. Or consider the case that the file system
is rearranged, and all the file pointers become stale.

It is not uncommon to use this approach in SQL Server though, and
the main reason is probably that the image data type has been difficult
to work with. (Which has nothing to do with its binary-ness to do, but
it's largeness.) With the advent of varbinary(MAX) in SQL 2005, there
may be less reason for this.
2) If this is a serious problem, then use an image base tool. IBM has
one that lets you make a drawing as the query and it will pull out the
ones that are closest; there are several products that do nothign but
face and fingerprint matching; CAD systems that handle 3D objects; etc.

SQL is not the answer to everything.


But it's surprising to hear that it's not the tool to store data.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 30 '06 #9
> #1 is what we do and it works really well.

What's your backup/recovery strategy? What happens if someone replaces
a file? Overwrites the file without changing datetime stamp? Renames a
folder? How do you know that your data has been corrupted / messed up
with?

Jan 30 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
I'm trying to read up on the rfc's that govern form inputs. Much of what I'm reading is stuff I didn't know before and some of it is alarming. This one left with me questions: ...
21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
3
by: Roberto | last post by:
I have the following problem: I have the following form client side: <FORM.......> <FORM action="./WZUpload.asp" method="Post" enctype="multipart/form-data" WIDTH=100%> <INPUT Type="file"...
1
by: Universal | last post by:
store Images (or any Binary Data) to a SQL Server database using VC++ Can anybody help me in this Thanks in advance
3
by: Sunny | last post by:
Hi all, I'm creating client/server app in C# (VS. 2003). So, I need the client to call the server with some auth info (user and pass). If the auth is OK, server will do some work and will prepare...
4
by: serge | last post by:
I was working on figuring out where a certain application was storing the multiple selection choices I was doing through the app. I finally figured out that they were being store in an IMAGE data...
0
by: Chris3000 | last post by:
Hi everyone How can I embeded an image to OLE Object field using Long Binary data. and what Long Binary data means and how to use it. does anyone have any ideas on I would to display...
4
by: Ty | last post by:
I have a SQL server 2000 DB that Ihave copied onto my PC and am using SQL server express 2005 to view. I created a project in VB.net and am reading the data out of the DB using...
0
by: Mr. Clean | last post by:
I need to store flags for the display of comments in our application. I would like to use a bit mas to determine if the flag is set, this flag can have up to 16 combinations from these values: ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.