Tuesday, March 27, 2012

Default image in SQL Server

Hi,

Is it at all possible to have a default image in an image field in sql server?

If so how?

Thanks,

JB::Is it at all possible to have a default image in an image field in sql server?

Yes.

::If so how?

Post insert trigger. If nothing is in (the inserted field), update the value with the default image.|||thona,

Many thanks for your reply.

This is what I need - If the user does not upload an image, then I need to set a default image in its place.

If I need to make a trigger, how do I trigger the default image.
I would need to know the binary data of the default image, no?

Can we access this binary data once we store it in a field of type 'image?'
I am probably making this harder than it is, although both myself and another guy have been posting trying to solve this one.

What on earth would you put in the default value box for a field of type image?

Thanks,
JB|||::If I need to make a trigger, how do I trigger the default image.

RTFM. I assume you have not read up the documentation about triggers. Why do you not do so before coming here first? I pointed to in the correct direction. Looking up the documentation would have answered this (keyword to look for: trigger).

::I would need to know the binary data of the default image, no?

Depends. Maybe you can have an esxternal hardare device that connects to a crystal ball. Sorry to sound sarcastiv, but this is obvious: if you want to set a default value, you naturally HAVE TO KNOW the default value.

::Can we access this binary data once we store it in a field of type 'image?'

No, SQL Server allows you to store data buit not to retrieve it.

Heck, what do you think they store it for - what value would data stored in a database have if you are not able to retrieve it again?

Sure you can access data in a SQL Server once it is stored.

::What on earth would you put in the default value box for a field of type image?

Who am I to tell you this?

Image is a storage for binary data (not a picture) per definition.

Without KNOWING the project, how do you think I could propose a sensible default value? This is totally dependant on the context.

::I am probably making this harder than it is, although both myself and another guy have
::been posting trying to solve this one.

With all respect, your questions show a tremendous amount of cluelessness. I mean, given the "can we access this data once we store it" is either a very badly formulated question, or it indicates you ahve no clue what you are doing and have no clue about the tools you deal with.

Btw - I would suggeest getting some books and reading documentation. That you can use a post insert trigger to set a default value should be well known - it is not necessarily something you think of in the first moment.

But this second batch of questions really gives me the idea you better need to get some basics in what SQL databases are for.|||I have read the documentation and I cannot find anywhere where it tells us how to set a default for a field type of "image." This data is stored as Binary Data.

In my app, users upload their images and are stored in sql server in a field type "image"
If they do not upload an image, I need to be able to define either a default or somehow send my own image to the database.

I have re-read about triggers in books online, but cannot find an answer how to do this.

thona, please help if you can. This is not such a simple question. Books online is extensive and this forum should help us find the answers we need quickly.

Thanks
JB|||::If they do not upload an image, I need to be able to define either a default or somehow
::send my own image to the database.

Then why d o you not do it?

The way you describe it ("send my own image to the database") is a code issue - something you do in your program. No need to store this image in the database.

::I have re-read about triggers in books online, but cannot find an answer how to do this.

* Create a post insert trigger
* Check the inserted colukmns list for allcolumns that hava NULL in the image
* Update the image with some other value for these entries.

SQL 101 once you get over the CREATE TRIGGER statement.

No comments:

Post a Comment