Question

  Asked: Dec 20 2007   6:03 PM GMT
  Asked by: Hank1039


Using MAX data types in SQL Server


SQL Server, Data management and storage, MAX

I'm new to using large data types (varchar(max))and after reading an article (Using MAX data types in SQL Server) I have a few questions.
I am trying to understand how you insert such a long string (up to 2 billion char) in the database table? I am assuming this would include storing Word Documents, etc. in the data base. If this is true, what is the method used to store the document in the data base? What is the max length of the Command String that is submitted to SQL Server?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   1
  •  -1



You can insert data using a standard insert statement if you'd like. Most people will write a stored procedure which accepts the blob data as an input parameter and then the stored procedure will do the actual insert. You can then call the procedure from your calling application in a parameterized mode so that you don't have to write the actuall execute command.

Your stored procedure would look something like this.

CREATE PROCEDURE usp_InsertWorkDoc
@FileName nvarchar(255),
@FileData varbinary(max)
AS
INSERT INTO FileTable
(FileName, FileData)
values
(@FileName, @FileData)
GO


You will want to put some data checking to make sure that the file doesn't already exist. You'll also notice that I used the varbinary(max) data type. Word Docs are binary are as such need to be stored in a binary data type.

_______
Thanks, Hank1039
  • AddThis Social Bookmark Button

Browse more Questions and Answers on SQL Server, DataManagement and Development.

Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny  |   Feb 22 2008  4:55AM GMT

Did this answer your question?