0

There is a table named "position" in my database. Following is the create table statement for it:

CREATE TABLE Position(  
Position_ID INT PRIMARY KEY NOT NULL,  
Position_Name VARCHAR(15) UNIQUE NOT NULL,  
Base_salary DECIMAL (10,2),  
Base_billing_hours_per_quarter INT (5) NOT NULL,  
Billing_rate VARCHAR (5)   
);  

I am supposed to add the following constraint to this table:

A new column called SalaryMultiplier should be specified to the table. The content of the salary multiplier column should contain the outcome of the following equation:

`salarymultiplier = (BaseBillingHoursPerQuarter*BillingRate)/(BaseSalary/4)`

The sample data for the columns are given below

Position ID = 1 
Position= Drafter 
BaseSalary= $32000    
BaseBillingHoursPerQuater= 260  
BillingRate= $40

How do I create the column and populate it with the proper value?

Taegost
  • 1,208
  • 1
  • 17
  • 26
Ayyub
  • 53
  • 2
  • 9
  • It's unclear what you're asking. Please include a code example. Also, what have you tried? What is happening? Is there an error? – Taegost Jun 22 '16 at 12:48
  • I edited the post please check. thankyou for your help – Ayyub Jun 22 '16 at 18:02
  • That looks much better. Now what have you tried? Are you getting an error? – Taegost Jun 22 '16 at 18:03
  • So are you trying to add a constraint that verifies that the data in the salaryMultiplier column matches that formula exactly, or to calculate the value of the salaryMultiplier column whenever a record is saved? – Taegost Jun 22 '16 at 18:08
  • i have done the create table and insert into statements. now i need to know how to add the new column to the table by doing the above mentioned calculation – Ayyub Jun 22 '16 at 18:13
  • It should calculate the salarymultiplier column automatically whenever a record is saved – Ayyub Jun 22 '16 at 18:15
  • I updated the verbiage of the question to reflect your needs, it's technically not a constraint – Taegost Jun 22 '16 at 18:18
  • thankyou for your help – Ayyub Jun 22 '16 at 18:29

1 Answers1

0

There are no check constraints in MySQL

Community
  • 1
  • 1
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
  • After clarification, this question isn't about constraints at all, even though that's what was initially stated – Taegost Jun 22 '16 at 18:18