?
Solved

Sql query to insert unique url in sql server 2000 database.

Posted on 2009-07-07
3
Medium Priority
?
378 Views
Last Modified: 2012-05-07
Hi,

I have sql insert query that is used to add url in th database. Suppose
urltitle="google"" and url="http://www.google.com" is present in the database.
I dont want same url url="http://www.google.com" will insert again.

here is my insert query
INSERT INTO linkstable (UrlTitle, Url, UserID,DateTimeStamp)
VALUES ('google','http://www.google.com','sam',GETDATE())

UrlID is the  primary key. I dont want that user can add same url again in the database if its present

thanks
0
Comment
Question by:Saroj13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24796897

either you can create a unique key on the url column or u can modify the query like this
INSERT INTO linkstable (UrlTitle, Url, UserID,DateTimeStamp)
SELECT  'google','http://www.google.com','sam',GETDATE()
Where not exists (SELECT 1 from linkstable WHERE url = 'http://www.google.com' )
0
 

Author Comment

by:Saroj13
ID: 24797238
I cant set unique key to url column as my primary key is urlid.

0
 
LVL 2

Expert Comment

by:kbac
ID: 24803053
Yes you can

Open designer, right click on any column, select indexes, say add, and after selecting the new index, change the column to url column and say yes to unique parameter.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question