I am trying to put an index on a column that will hold URLs. Since the maximum length of a URL an be over 2000 characters long I set the data type to NVARCHAR(3000). When I did this I got the error The total size of an index or primary key cannot exceed 900 bytes
. Since I may need to search for records by URL i will need an index on my URL Column. Is there a way around this limitation?
Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'IDX_EStrat' has maximum length of 5000 bytes. For some combination of large values, the insert/update operation will fail.
In SQL Server you can include non-key columns in a nonclustered index, to avoid the limitation of a maximum of 32 key columns. For more information, see Create Indexes with Included Columns.
The total amount of space used to store an individual row of data in SQL Server cannot exceed 8,060 bytes. The reason for the 8,060-byte limit is simple.
No, you may have upto 1,000 columns in a table these days.
You could create a computed column for the checksum of the URL and then use the checksum in the query. Checksums will not be unique, but it will quickly narrow down the number of possible matches.
First, add a computed column to your table, like this:
Alter Table YourTableName Add URL_HASH As CheckSum(URL)
Now index the column like this:
Create Index idx_YourTableName_URL_HASH On YourTableName(URL_HASH)
Now you can write a query that will do an index seek to find the row you are looking for:
Select URL
From YourTableName
Where URL_HASH = CheckSum(N'google.com')
And URL = 'google.com'
This method should work very well for exact matches. If you want partial matches, you're better off using the full text search functionality.
SQL Server Full Text search is what you'll probably want.
http://msdn.microsoft.com/en-us/library/ms142571.aspx
You have to jump through some minor hoops with setting it up vs a simple index but it shouldn't be super hard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With