Solved

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

Posted on 2009-07-07
3
360 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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