Question

In: Computer Science

How to populate an SQL table that has two PK (foreign) that have different number of...

How to populate an SQL table that has two PK (foreign) that have different number of rows?

Example:

there are 3 tables. student, assigment, and hoursDedicated.

there are 5 students, and 3 assigments, and x hoursDedicated.

hoursDedicated has 2 Primary Keys, studentID and assigmentID. how do you populate hoursDedicated??

Thank you for your time.

Solutions

Expert Solution

This demonstration is using SQL Server.All this data is used for demonstration purpose only.

1.Table Name :student
create table student(
StudentId int primary key,
StudentName varchar(20));

/*inserting reconrds into student table*/
insert into student values (1,'S1');
insert into student values (2,'S2');

/*select student data*/
select * from student;'

Screen in SQL Server :

**********************************************

2.Table Name :assigment
create table assigment(
assignmentID int primary key,
assignmentName varchar(20));

/*inserting records into assignment table*/
insert into assigment values (1,'A1');
insert into assigment values (2,'A2');
insert into assigment values (3,'A3');

/*selecting data from assigment*/
select * from assigment;

Screen in SQL Server :

************************************************

3.Table Name :hoursDedicated
create table hoursDedicated(
StudentId int ,
assignmentID int,
hours decimal(6,2),
primary key(StudentId,assignmentID),
foreign key (StudentId) references Student(StudentId),
foreign key (assignmentID) references assigment(assignmentID));

/*inserting records into hoursDedicated table*/
insert into hoursDedicated values(1,1,5);
insert into hoursDedicated values (1,2,8);
insert into hoursDedicated values (1,3,5.2);
insert into hoursDedicated values (2,1,5.2);

/*selecting records*/
select * from hoursDedicated;

Screen in SQL Server :

********************************************


Related Solutions

Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table:...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table: Market, Region, ProductFamily, Manager (all Managers must have different % commissions, Commission is an attribute of the Manger). 2. Insert 5 records in Agent using all Managers 3. Insert 15 records in Product using  all ProductFamily 4. Insert 15 records in Customer using various Regions and Markets 5. Insert 50 records in SalesOrder using various Customers, Products, Agents Notes : ALL the Names ( Description)...
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title,...
SQL 9. Link the following two tables: HumanResources.Employee and Sales.SalesPerson then display Employee PK, job title, Date of birth, Gender, Sales quotas, Commission percent and bonus. Use an outer join to display all the employee whether they are in sales or not. Make sure to sort by bonus desc. Explain why some of the field from the Sales.SalesPerson table are null.
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
Write an SQL command that creates a SHOP table. The table should have a shop_id, a shop_name, a shop_location
Write an SQL command that creates a SHOP table. The table should have a shop_id, a shop_name, a shop_location
Question 3 The following table shows the foreign exchange quotation of two different banks Bank X...
Question 3 The following table shows the foreign exchange quotation of two different banks Bank X Bid price of US dollars GH¢5.40 Ask price of US dollars GH¢5.45 Bank Y GH¢5.39 GH¢5.44 a) Given the above information, briefly explain whether locational arbitrage is possible or not. If it is possible, explain the steps involved in taking advantage of the locational arbitrage, and compute the profit from this arbitrage if you had one million Ghana Cedis (GH¢1,000,000). b) Calculate the bid/ask...
Question 3 The following table shows the foreign exchange quotation of two different banks Bank X...
Question 3 The following table shows the foreign exchange quotation of two different banks Bank X Bank Y Bid price of US dollars GH¢5.40 GH¢5.39 Ask price of US dollars GH¢5.45 GH¢5.44 a) Given the above information, briefly explain whether locational arbitrage is possible or not. If it is possible, explain the steps involved in taking advantage of the locational arbitrage, and compute the profit from this arbitrage if you had one million Ghana Cedis (GH¢1,000,000). b) Calculate the bid/ask...
The following table shows the foreign exchange quotation of two different banks Bank X Bid price...
The following table shows the foreign exchange quotation of two different banks Bank X Bid price of US dollars GH¢5.40 Ask price of US dollars GH¢5.45 Bank Y GH¢5.39 GH¢5.44 a) Given the above information, briefly explain whether locational arbitrage is possible or not. If it is possible, explain the steps involved in taking advantage of the locational arbitrage, and compute the profit from this arbitrage if you had one million Ghana Cedis (GH¢1,000,000). b) Calculate the bid/ask spread for...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from your choice with different data types.
Over the years, people have had a number of different choices in how to access the...
Over the years, people have had a number of different choices in how to access the news. Researchers used one sample of 15 people, over the age of 40, to see how many hours they each accessed the news on both tv and radio each week. The results from the 15 people are as follows: TV: 22, 8, 25, 22, 12, 26, 22, 19, 21, 23, 14, 14, 14, 16, 24 Radio: 25, 10, 29, 19, 13, 28, 23, 21,...
How have the ideas of Isolationism and Interventionism been articulated in US foreign policy? How has...
How have the ideas of Isolationism and Interventionism been articulated in US foreign policy? How has Donald trump approached foreign policy? And how should the US deal with Iran, a country who wants to create nuclear weapons?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT