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

  • SEARCH
  • Home
  • 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 6977923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:41:17+00:00 2026-05-27T17:41:17+00:00

i’m working on a webpage indexing robot and using php and mysql. one of

  • 0

i’m working on a webpage indexing robot and using php and mysql. one of the tables will be to store the list of webpages. i want that table to have an integer based id column (so that i can join it to other tables more quickly, and so that other tables can reference it without storing the complete url in a column), but i also want the url column to remain unique.

the reason this question has come up is that if my script reads a web page that has 250 links i’m not sure the best way to add them to the webpages table without creating duplicates. i could loop the 250 links that i found and query the table for each of them to make sure they don’t exist, and then insert the ones that do – which would require at least 250 queries.

however, if i could have mysql enforce the url to be a unique column i could simply do one insert ignore, statement with all of the links. this would keep the existing records from being duplicated while adding new ones. if i had this type of table with an integer id column that is unique / primary and auto-incremented, could i also specify that the url column be unique?

  id (auto inc)     url                            added
----------------------------------------------------------------------
  1                 http://site.com/page-a/        2010-01-01 01:23:34
  2                 http://site.com/page-b/        2010-01-01 01:23:34
  3                 http://site.com/page-c/        2010-01-01 01:23:34

another option that has crossed my mind is setting the url to be a unique primary key, and then manually incrementing the id column with php / mysql statements:

url (unique, primary)         id          added
-------------------------------------------------------------
http://site.com/page-a/       1           2010-01-01 01:23:34
http://site.com/page-b/       2           2010-01-01 01:23:34
http://site.com/page-c/       3           2010-01-01 01:23:34

it seems like that would have the benefit of allowing mysql to enforce a unique url column (and thus allowing my insert ignore method), and also allowing me to join on an integer. the only weird thing is having to rely on my script to add and increment the id column, but i may be willing to do that if there is not a better option.

what are my options?

  • 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. Editorial Team
    Editorial Team
    2026-05-27T17:41:18+00:00Added an answer on May 27, 2026 at 5:41 pm

    Yes, you can make the url column unique. So a big INSERT IGNORE INTO ... (...) VALUES (...), (...), ... will do the job.

    Do NOT make url primary though! Your primary key should be the id auto_increment field; simply create a unique index on the url field.

    Don’t forget that INSERT IGNORE is MySQL-specific though so if you ever plan to support e.g PostgreSQL, too, your code won’t work.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

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.