programming4us
programming4us
DATABASE

SQL Server 2008 : Transact-SQL Programming - The max Specifier

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
In SQL Server 2000, the most data that could be stored in a varchar, nvarchar, or varbinary column was 8,000 bytes. If you needed to store a larger value in a single column, you had to use the large object (LOB) data types: text, ntext, or image. The main disadvantage of using the LOB data types is that they cannot be used in many places where varchar or varbinary data types can be used (for example, as local variables, as arguments to SQL Server string manipulation functions such as REPLACE, and in string concatenation operations).

SQL Server 2005 introduced the max specifier for varchar and varbinary data types. This specifier expands the storage capabilities of the varchar and varbinary data types to store up to 231-1 bytes of data, which is the same maximum size of text and image data types. The main difference is that these large value data types can be used just like the smaller varchar, nvarchar, and varbinary data types. The large value data types can be used in functions where LOB objects cannot (such as the REPLACE function), as data types for Transact-SQL variables, and in string concatenation operations. They can also be used in the DISTINCT, ORDER BY, and GROUP BY clauses of a SELECT statement as well as in aggregates, joins, and subqueries.

The following example shows a local variable being defined using the varchar(max) data type:

declare @maxvar varchar(max)
go

However, a similar variable cannot be defined using the text data type:

declare @textvar text
go

Msg 2739, Level 16, State 1, Line 2
The text, ntext, and image data types are invalid for local variables.declare
@maxvar varchar(max)



The remaining examples in this section make use of the following table to demonstrate the differences between a varchar(max) column and text column:

create table maxtest (maxcol varchar(max),
textcol text)
go
-- populate the columns with some sample data
insert maxtest
select replicate('1234567890', 1000), replicate('1234567890', 1000)
go

In the following example, you can see that the substring function works with both varchar(max) and text data types:

select substring (maxcol, 1, 10),
substring (textcol, 1, 10)
from maxtest
go
maxcol textcol
---------- ----------
1234567890 1234567890

However, in this example, you can see that while a varchar(max) column can be used for string concatenation, the text data type cannot:

select substring('xxx' + maxcol, 1, 10) from maxtest
go

----------
xxx1234567

select substring('xxx' + textcol, 1, 10) from maxtest
go

Msg 402, Level 16, State 1, Line 1
The data types varchar and text are incompatible in the add operator.

With the introduction of the max specifier, the large value data types are able to store data with the same maximum size as the LOB data types, but with the ability to be used just as their smaller varchar, nvarchar, and varbinary counterparts. It is recommended that the max data types be used instead of the LOB data types because the LOB data types will be deprecated in future releases of SQL Server.

Other  
  •  SQL Server 2008 : T-SQL Tips and Tricks (part 3) - Generating T-SQL Statements with T-SQL & De-Duping Data with Ranking Functions
  •  SQL Server 2008 : T-SQL Tips and Tricks (part 2) - Using CONTEXT_INFO & Working with Outer Joins
  •  SQL Server 2008 : T-SQL Tips and Tricks (part 1) - Date Calculations & Sorting Results with the GROUPING Function
  •  SQL Server 2008 : General T-SQL Performance Recommendations
  •  SQL Server 2008 : General T-SQL Coding Recommendations (part 2) - Avoid SQL Injection Attacks When Using Dynamic SQL & Comment Your T-SQL Code
  •  SQL Server 2008 : General T-SQL Coding Recommendations (part 1) - Provide Explicit Column Lists & Qualify Object Names with a Schema Name
  •  SQL Server 2008 : Advanced Stored Procedure Programming and Optimization - Using Extended Stored Procedures
  •  SQL Server 2008 : Advanced Stored Procedure Programming and Optimization - Installing and Using .NET CLR Stored Procedures
  •  SQL Server 2008 : Advanced Stored Procedure Programming and Optimization - Using Dynamic SQL in Stored Procedures
  •  SQL Server 2008 : Advanced Stored Procedure Programming and Optimization - Stored Procedure Performance
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us