Solved

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

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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