Question

In: Computer Science

1) Create a table “college” that has as attributes name, city name, state/province/region name, country name,...

1) Create a table “college” that has as attributes name, city name, state/province/region name, country name, and year in which the college was established as well as an ID as primary key. Insert records for 5 colleges of your choice, including one or more you have attended.

2) Create a table “student” that has as attributes first name, last names, and college ID for students, and insert the names of yourself and friends who attended one or more colleges together with you (if you have only attended one college, the name can be the same for all). Note that the student names can be fictitious but not the college name.

3) Add a foreign key to the appropriate table above, using “on delete cascade” as referentially triggered action, and demonstrate that insertion for a student record with a non-existing college ID fails.

4) Do a query that shows all students together with their respective college information. For colleges, that no students have attended, list all student information as null (i.e. OUTER JOIN).

5) Do a query that lists college names together with the number of students in the database that have attended that college, using the GROUP BY statement.

6) Do a query of catalog information.

7) Do a deletion of a college that was referenced and redo the query from question 4.

Solutions

Expert Solution

1)

command to create table , college:

CREATE TABLE college(name varchar(255), city_name varchar(255), state varchar(255), country varchar(255), year_of_establishment int(4), ID varchar(255) NOT NULL PRIMARY KEY);

command to insert record to college table:

INSERT INTO college VALUES("Om puri kori", "chinston","Ugoslavia", "UK","2003", "OPK123");

2)

command to create table student:

CREATE TABLE student(fname varchar(255), lname varchar(255), college_ID varchar(255));

command to insert student into table:

INSERT INTO student VALUES("abc", "xyz", "RTG123");

3)

Adding a foreign key to student table on column, coolege_ID:

ALTER TABLE student ADD FOREIGN KEY (college_ID) REFERENCES college(ID);

You can see below that when we tried to insert a student with non-existing college ID in the table, the query fails.

4)

We will do RIGHT OUTER JOIN as it will include every college even if it has no students.

SELECT fname, lname, name FROM student RIGHT OUTER JOIN college ON student.college_ID = college.ID;

5)

SELECT name, count(fname) FROM student RIGHT OUTER JOIN college ON student.college_ID = college.ID GROUP BY college.ID;

6)

To query cayalog information, just show the table content of student and college tables.

SELECT * FROM student;

SELECT * FROM college;

7)

To delete a record with college ID = "SM123":

DELETE FROM college WHERE ID = "SM123";

And then redoing the query from part 4 gives following output:

If it helps you, do upvote as it motivates us a lot!


Related Solutions

Create a form that has the following fields: Name Address City Country (Please Select Country, US,...
Create a form that has the following fields: Name Address City Country (Please Select Country, US, Canada) State/Province (Drop Down List) Postal Code Submit Button Create two arrays of objects, one for US States, one for Canadian Provinces. The object should contain Name and Abbreviation. You don’t need to do all the states or provinces, just a few to make sure your code works. (3 OF EACH) When the user selects either US or Canada, populate the drop down using...
Company: Citigroup Company analysis: 1)Full company name; home office (city, state, country); name of CEO and...
Company: Citigroup Company analysis: 1)Full company name; home office (city, state, country); name of CEO and name of President or indicate if same; stock symbol; stock exchange where stock is traded; closing stock price as of the Friday before the date the project is due. 2)History of the company. Where was the company founded and who was/were the founders? Indicate any major events in the company’s history like mergers or acquisitions? 3)What primary industry does this company compete in and...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
Pick a local (city, region, or country) brand that has been very successful competing against the...
Pick a local (city, region, or country) brand that has been very successful competing against the bigger global brands in its product category. What are the elements of its strategy that have enabled it to achieve this success?
College Name State Public (1)/ Private (2) in-state tuition Berry College GA 2 8050 University of...
College Name State Public (1)/ Private (2) in-state tuition Berry College GA 2 8050 University of Massachusetts at Dartmouth MA 1 1836 Olivet College MI 2 10500 Saint Olaf College MN 2 14350 Francis Marion University SC 1 2920 Huron University SD 2 7260 Tennessee Technological University TN 1 1740 Abilene Christian University TX 2 7440 Southwestern Adventist College TX 2 7536 Radford University VA 1 2924 The attached Excel file has a sample of tuition rates at 10 colleges...
College Name State Public (1)/ Private (2) in-state tuition Berry College GA 2 8050 University of...
College Name State Public (1)/ Private (2) in-state tuition Berry College GA 2 8050 University of Massachusetts at Dartmouth MA 1 1836 Olivet College MI 2 10500 Saint Olaf College MN 2 14350 Francis Marion University SC 1 2920 Huron University SD 2 7260 Tennessee Technological University TN 1 1740 Abilene Christian University TX 2 7440 Southwestern Adventist College TX 2 7536 Radford University VA 1 2924 The attached Excel file has a sample of tuition rates at 10 colleges...
Pick a local brand (from your city, region, or country) that has been very successful competing...
Pick a local brand (from your city, region, or country) that has been very successful competing against bigger global brands in its product category Explore and determine if the local brand you picked has a well-defined and executed brand strategy? What are the elements of the local brand strategy that enabled it to achieve this success? minimum 250 words
Pick a local brand (from your city, region, or country) that has been very successful competing...
Pick a local brand (from your city, region, or country) that has been very successful competing against bigger global brands in its product category Explore and determine if the local brand you picked has a well-defined and executed brand strategy? What are the elements of the local brand strategy that enabled it to achieve this success? Submit an initial quality post in which you discuss and defend your list of elements with your classmates.
Pick a local brand (from your city, region, or country) that has been very successful competing...
Pick a local brand (from your city, region, or country) that has been very successful competing against bigger global brands in its product category Explore and determine if the local brand you picked has a well-defined and executed brand strategy? What are the elements of the local brand strategy that enabled it to achieve this success?
The client has inventory at approximately 50 locations in a three-province region. The inventory is difficult...
The client has inventory at approximately 50 locations in a three-province region. The inventory is difficult to count and can be observed only by travelling by automobile. The internal controls over acquisitions, cash disbursements, and perpetual records are considered effective. This is the fifth year that you have done the audit, and audit results in past years have always been excellent. The client is in excellent financial condition. Required Recommend an evidence mix for the five types of tests for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT