Solved

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

Posted on 2009-07-07
3
341 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
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now