|
|
|
This shows some of the cool, powerful techniques of SQL2000 viz. COLLATION, BINARY_CHECKSUM functions. |
Click here to copy the following block | USE tempdb; Go
CREATE TABLE CaseTest ( Col1 varchar( 30 ) COLLATE SQL_Latin1_General_CP1_CI_AI ); go
CREATE CLUSTERED INDEX IX_CaseTest_Col1 ON CaseTest( col1 ) ; go INSERT INTO CaseTest VALUES( 'Test String.' ); Go
SET SHOWPLAN_TEXT ON; GO DECLARE @SearchStr varchar( 30 ); SET @SearchStr = 'test string.';
SELECT * FROM CaseTest AS t1 WHERE t1.Col1 COLLATE SQL_Latin1_General_CP1_CS_AS = @SearchStr;
SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr And t1.Col1 COLLATE SQL_Latin1_General_CP1_CS_AS = @SearchStr;
SET @SearchStr = 'Test String.'; SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr And t1.Col1 COLLATE SQL_Latin1_General_CP1_CS_AS = @SearchStr; GO
DECLARE @SearchStr varchar( 30 ); SET @SearchStr = 'test string.';
SELECT * FROM CaseTest AS t1 WHERE BINARY_CHECKSUM( t1.Col1 ) = BINARY_CHECKSUM( @SearchStr );
SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr And BINARY_CHECKSUM( t1.Col1 ) = BINARY_CHECKSUM( @SearchStr );
SET @SearchStr = 'Test String.'; SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr And BINARY_CHECKSUM( t1.Col1 ) = BINARY_CHECKSUM( @SearchStr ); GO SET SHOWPLAN_TEXT OFF; GO
ALTER TABLE CaseTest ADD Col1BinChkSum AS ( BINARY_CHECKSUM( Col1 ) ); CREATE NONCLUSTERED INDEX IX_CaseTest_Col1_BinaryCheckSum ON CaseTest( Col1BinChkSum ); GO
INSERT INTO CaseTest VALUES( 'test string.' );
SELECT * FROM CaseTest;
GO
SET SHOWPLAN_TEXT ON; GO DECLARE @SearchStr varchar( 30 ); SET @SearchStr = 'test string.';
SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr;
SELECT * FROM CaseTest AS t1 WHERE t1.Col1BinChkSum = BINARY_CHECKSUM( @SearchStr );
SET @SearchStr = 'Test String.'; SELECT * FROM CaseTest AS t1 WHERE t1.Col1BinChkSum = BINARY_CHECKSUM( @SearchStr );
GO
DECLARE @SearchStr varchar( 30 ); SET @SearchStr = 'test string.';
SELECT * FROM CaseTest AS t1 WHERE CAST( t1.Col1 AS varbinary( 10 ) ) = CAST( @SearchStr AS varbinary( 10 ) );
SET @SearchStr = 'Test String.';
SELECT * FROM CaseTest AS t1 WHERE t1.Col1 = @SearchStr And CAST( t1.Col1 AS varbinary( 10 ) ) = CAST( @SearchStr AS varbinary( 10 ) );
GO SET SHOWPLAN_TEXT OFF; GO
DROP TABLE CaseTest; GO |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|