Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 49671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:28:24+00:00 2026-05-10T16:28:24+00:00

What is the best way to deal with storing and indexing URL’s in SQL

  • 0

What is the best way to deal with storing and indexing URL’s in SQL Server 2005?

I have a WebPage table that stores metadata and content about Web Pages. I also have many other tables related to the WebPage table. They all use URL as a key.

The problem is URL’s can be very large, and using them as a key makes the indexes larger and slower. How much I don’t know, but I have read many times using large fields for indexing is to be avoided. Assuming a URL is nvarchar(400), they are enormous fields to use as a primary key.

What are the alternatives?

How much pain would there likely to be with using URL as a key instead of a smaller field.

I have looked into the WebPage table having a identity column, and then using this as the primary key for a WebPage. This keeps all the associated indexes smaller and more efficient but it makes importing data a bit of a pain. Each import for the associated tables has to first lookup what the id of a url is before inserting data in the tables.

I have also played around with using a hash on the URL, to create a smaller index, but am still not sure if it is the best way of doing things. It wouldn’t be a unique index, and would be subject to a small number of collisions. So I am unsure what foreign key would be used in this case…

There will be millions of records about webpages stored in the database, and there will be a lot of batch updating. Also there will be a quite a lot of activity reading and aggregating the data.

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:28:24+00:00Added an answer on May 10, 2026 at 4:28 pm

    I’d use a normal identity column as the primary key. You say:

    This keeps all the associated indexes smaller and more efficient but it makes importing data a bit of a pain. Each import for the associated tables has to first lookup what the id of a url is before inserting data in the tables.

    Yes, but the pain is probably worth it, and the techniques you learn in the process will be invaluable on future projects.

    On SQL Server 2005, you can create a user-defined function GetUrlId that looks something like

    CREATE FUNCTION GetUrlId (@Url nvarchar(400))  RETURNS int AS BEGIN   DECLARE @UrlId int   SELECT @UrlId = Id FROM Url WHERE Url = @Url   RETURN @UrlId END 

    This will return the ID for urls already in your URL table, and NULL for any URL not already recorded. You can then call this function inline your import statements – something like

    INSERT INTO    UrlHistory(UrlId, Visited, RemoteIp)  VALUES    (dbo.GetUrlId('http://www.stackoverflow.com/'), @Visited, @RemoteIp) 

    This is probably slower than a proper join statement, but for one-time or occasional import routines it might make things easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer A DLL is an assembly, whereas an assembly can be… May 11, 2026 at 2:14 pm
  • added an answer The 'ScriptMaps' property is where the configuration mappings get stored.… May 11, 2026 at 2:14 pm
  • added an answer Swig makes JNI easier too. In terms of speed, I… May 11, 2026 at 2:14 pm

Related Questions

What is the best way to deal with storing and indexing URL's in SQL
What is the best way to deal with XML documents, XSD etc in C#
What is the best way to verify/test that a text string is serialized to
What is the best way to authorize all users to one single page in
What is the best way to store international addresses in a database? Answer in
So, I've been doing Java for a number of years now, but now I'm
We are planning on adding multi-language support for our ASP.NET Website. I understand the
The project I am working on requires some executions to be done at a
I am looking for a way to extract / scrape data from Word files

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.