SQL Server2005 data Type maximum value

Source: Internet
Author: User
Tags file system sql server query types of functions

Things started very simply. Megaware's marketing department wants a new Web site to publish documents, and the development team feels that using a SQL Server 2000 database as a document storage repository makes things easier. Steve is Megaware's database administrator and doesn't see the big problem; storing documents in a database, rather than using a file system, means that the server needs to do more, but it also makes backup and management much easier. It should also be impossible for the database to become unsynchronized with the file system.

Many of the documents the marketing department wants to store are more than 8,000 bytes long, so obviously varchar is not the right type of data for this job. As an alternative, the text data type is used to define the fields where the data is stored. Because each text can accommodate 2GB of content, text to store the marketing department's colleagues throw into the database the largest file is no problem.

Months later, the market filled the entire database with a lot of boring copies. But that's not what Steve really cares about. The database is humming happily and everyone is satisfied with the results of the project.

Until the company's slogan changed that big day. The marketing team thinks "Megaware:it's really cool!" Sounds better than the original "It" Megaware ' s Way or the highway!. Because the marketing team has embedded the original banner in the footer of every document in the warehouse, Steve's job is to change the footer of all these documents.

"No problem," Steve thought, opening the SQL Server Query Analyzer tool to perform the following T-SQL batch:

UPDATE MarketingDocuments

SET Document =

REPLACE(Document,

'It''s MegaWare''s Way or the Highway!',

'MegaWare: It''s really cool!)

When he saw the error message, Steve's relaxed smile soon disappeared, "The parameter 1,text of the substitution function is invalid." ”

When the substitution function is written, it does not work on the text data type. It also does not work for charindex or substring-or at least they do not work in more than 8,000 characters. Further, developers forget to handle local variables of the text or image type, and do not actually support any operations. Even a simple update of a substring in a document requires obscure things, as well as READTEXT and WRITETEXT functions that are difficult to use. Rather than being a developer or a busy database administrator, it takes time to use different types of functions to figure out how to use them correctly.

SQL Server developers are fortunate that they will be able to push through the clouds and see the blue sky. SQL Server 2005 introduces a series of new data types called Max. This is an extension of the Varchar,nvarchar and varbinary types, which were previously limited to less than 8000 bytes. Max can hold up to 2GB of data, just like text and image-and fully compatible with all of the SQL Server's built-in string functions.

Using the MAX keyword to define a variable of one of the max types is as simple as the size of the substitution string (when varchar/nvarchar) or byte (for varbinary).

DECLARE @BigString VARCHAR(MAX)

SET @BigString = 'abc'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.