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 6813995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:38:07+00:00 2026-05-26T20:38:07+00:00

I have Plan table that has a one to many relationship with a Price

  • 0

I have Plan table that has a one to many relationship with a Price table.
(1 plan can have many prices)

However the problem is I have another table called “StandardPrices” that holds the names of all the prices (The reason for this is I want to be able to add or remove prices at any time)

 Plan Table:
 ID int primary key,
 plan Name varchar(200),
 ...

 PriceTable:
 ID int primary key,
 PlanId int foreign key references plan(ID)
 PriceName ID foreign key standardprices(id)

 StandardPrices:
 ID int primary key,
 PriceName varchar(200),
 DefaultPrice money

So whenever a plan is created, it automatically creates a List of all the prices in the StandardPrice list (with default values).

The problem I have, Is I need, whenever I create a new StandardPrice, it automatically checks if that price exists in every plan, and if it doesnt, create an entry in the price table for that planid.

I use Stored procedures and thought the best way to do this would be through SQL.

When StandardPrices are created:

   begin      
   insert into StandardPrices (PriceName, Defaultprice)
       values (@priceName, @DefaultPrice)
   end

   begin
   //list all plans.
   //cross reference PriceTable to see if plan exists
   //if not insert priceplan with default value
   end

I am a bit confused how i can implement such a sql command?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T20:38:07+00:00Added an answer on May 26, 2026 at 8:38 pm

    I think it looks something like this:

    insert into PriceTable (PlanId, PriceName)
    select PlanId, @priceName
    from Plan
    where not exists 
      (select null from PriceTable where PriceTable.PlanId = Plan.PlanId)
    

    And you should probably do this as part of an INSERT trigger on your database.

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

Sidebar

Related Questions

I have a database structure that has two one-to-many relationships. I have a website,
I have an abstract user control(baseModule) that has a property that I plan on
I have a table I'm working on that has around 3 million tuples. It
I have a table that have a Certificate # column and a Plan-Phase column,
I have a complex MySQL query that joins three tables and self-joins one table
I currently have a site with a table that has Lat/Long float columns, and
Suppose I have a database table with columns a, b, and c. I plan
We have a daily maintenance plan in SQL Server 2005 that performs a full
I have a constant value that I only plan to use once in my
I have two tables, one has about 1500 records and the other has about

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.