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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:29:48+00:00 2026-05-11T11:29:48+00:00

I asked this question previously but the answers weren’t what I was looking for.

  • 0

I asked this question previously but the answers weren’t what I was looking for.

I created a table in Asp.net without using code. It contains two columns.

YourUserId and FriendUserId

This is a many to many relationship.

Heres what I want:

There can be multiple records with your name as the UserId, there can also be multiple records with FriendUserId being the same…but there cannot be multiple records with both being the same. For example:

Dave : Greg

Dave : Chris

Greg : Chris

Chris : Greg

is good

Dave : Greg

Dave : Greg

is not good.

I right clicked on the table and chose Indexes/Keys. I then put both columns in the columns section and chose to make the unique. I thought this would make them unique as a whole but individually not unique.

If you go to the Dataset, it show keys next to both columns and says that there is a constraint with both columns being checked.

Is there a way of just making sure that you are not inserting a duplicate copy of a record into the table without individual columns being unique?

I tried controling it with my sql insert statement but that did not work. This is what I tried.

INSERT INTO [FriendRequests] ([UserId], [FriendUserId]) VALUES (”+UserId+”, ”+PossibleFriend+”) WHERE NOT EXIST (SELECT [UserId], [FriendUserId] FROM [FriendRequests])

That didn’t work for some reason. Thank you for your help!

  • 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. 2026-05-11T11:29:48+00:00Added an answer on May 11, 2026 at 11:29 am

    You should create a compound primary key to prevent duplicate rows.

    ALTER TABLE FriendRequests ADD CONSTRAINT pk_FriendRequests PRIMARY KEY (UserID, FriendUserID) 

    Or select both columns in table designer and right click to set it as a key.

    To prevent self-friendship, you’d create a CHECK constraint:

    ALTER TABLE FriendRequests ADD CONSTRAINT ck_FriendRequests_NoSelfFriends CHECK (UserID <> FriendUserID) 

    You can add the check constraint in the designer by right clicking anywhere in the table designer, clicking ‘Check constraints’, clicking ‘add’, and setting expression to UserID <> FriendUserID

    You might want to look at this question

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer As others have noted, the number of tables is probably… May 11, 2026 at 2:11 pm
  • added an answer What you need is a Composite Application Block: Winforms: http://msdn.microsoft.com/en-us/library/aa480450.aspx… May 11, 2026 at 2:11 pm
  • added an answer It looks to me like you can't connect to a… May 11, 2026 at 2:11 pm

Related Questions

I asked a similar question about this previously, but I did not specify that
Ok, i've read most relevant questions asked here previously on this but I still
this question is an extension to a previous question i asked (and was answered).
This is a continuation question from a previous question I have asked I now
(I asked this question in another way , and got some interesting responses but
I asked this question previously but the answers weren't what I was looking for.
When writing an average new app in 2009, what's the most reasonable digest function
I previously asked about what Mixins were, and have begun to get the gist
I imagine this is a pretty hard question to answer without sitting down and
Yes, I realize this question was asked and answered, but I have specific questions

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.