Question

In: Computer Science

Using SQL create a new database called school_app. Create a student table with fields id (auto...

Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2, 3, or 4). Insert data into all the tables with at least 10 different students and at least 3 different courses (you must be one of the students). Make sure all the students are taking multiple courses and all courses have multiple students. Do not use the data from anyone else in this course. When finished, do a SELECT * for all three tables and copy/paste the results here:

If someone could help me with this, it would be greatly appreciated. Ill certainly give a thumbs up!

Solutions

Expert Solution

Here I am providing the answer for the above question:

SQL Code:

CREATE DATABASE school_app;

/* creaeting tables */
CREATE TABLE student
(
id INT IDENTITY(1,1) PRIMARY KEY,
first_name VARCHAR(20),
last_name VARCHAR(20)
);

CREATE TABLE course
(
id INT IDENTITY(1,1) PRIMARY KEY,
course_code VARCHAR(10),
course_number INT
);

CREATE TABLE student_course
(
student_id INT,
course_id INT,
grade INT,
FOREIGN KEY(student_id) REFERENCES student(id),
FOREIGN KEY(course_id) REFERENCES course(id)
);

/* Inserting the data */

INSERT INTO student(first_name,last_name) VALUES('vamsi','srivathsav');
INSERT INTO student(first_name,last_name) VALUES('swetha','koluboyina');
INSERT INTO student(first_name,last_name) VALUES('sai','manish');
INSERT INTO student(first_name,last_name) VALUES('deepu','desabattula');
INSERT INTO student(first_name,last_name) VALUES('sai','j');
INSERT INTO student(first_name,last_name) VALUES('devi','sabbella');
INSERT INTO student(first_name,last_name) VALUES('sri devi','thatha');
INSERT INTO student(first_name,last_name) VALUES('vimala','sahukari');
INSERT INTO student(first_name,last_name) VALUES('ravali','sakhinetipalli');
INSERT INTO student(first_name,last_name) VALUES('sandhya','barla');

INSERT INTO course(course_code,course_number) VALUES('ITC',100);
INSERT INTO course(course_code,course_number) VALUES('MAT',201);
INSERT INTO course(course_code,course_number) VALUES('CPP',304);

INSERT INTO student_course(student_id,course_id,grade) VALUES(1,2,5);
INSERT INTO student_course(student_id,course_id,grade) VALUES(1,1,5);
INSERT INTO student_course(student_id,course_id,grade) VALUES(1,3,4);
INSERT INTO student_course(student_id,course_id,grade) VALUES(2,3,4);
INSERT INTO student_course(student_id,course_id,grade) VALUES(2,1,4);
INSERT INTO student_course(student_id,course_id,grade) VALUES(2,2,3);
INSERT INTO student_course(student_id,course_id,grade) VALUES(3,1,4);
INSERT INTO student_course(student_id,course_id,grade) VALUES(3,2,3);
INSERT INTO student_course(student_id,course_id,grade) VALUES(4,3,2);
INSERT INTO student_course(student_id,course_id,grade) VALUES(4,2,4);
INSERT INTO student_course(student_id,course_id,grade) VALUES(4,1,5);

/* selecting data */

SELECT * FROM student;
SELECT * FROM course;
SELECT * FROM student_course;

Screenshot:

Output:

student table:

course table:

student_course table:


Related Solutions

You have a table called scholar where there are two fields id and create date. You...
You have a table called scholar where there are two fields id and create date. You want to create an ETL process that loads the data from scholar table into the big data platform. What are the different things that you will put on a requirement document for the developer to write code and implement the solution?
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -  (10...
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -   1) The name of a medicine, sanitizer, or tip/trick for protecting yourself against transmission or fight the disease - STRING 2) The amount of money the item costs - NUMBER 3) The UPC code of the item - NUMBER 4) Manufacturing country of the item - STRING Connect to the SQL database with your HTML code, and make sure to show the results of...
Write a SQL script to add another table to your database. Include these fields in your...
Write a SQL script to add another table to your database. Include these fields in your Product table: Field Name Description Data Type Sample Value ProductID Product ID integer 5 ProductName Product Name varchar(50) candle Description Product Description varchar(255) Bee’s wax candle picUrl Filename of the product’s picture varchar(50) candle.gif Price Product Price decimal 10.99           ProductID should be the Primary Key. It is an auto-increment field.           The Price field stores prices to 7 significant digits and to 2...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
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.
Create the actual database using SQL syntax. This is completed using a Database Application (i.e Microsoft...
Create the actual database using SQL syntax. This is completed using a Database Application (i.e Microsoft Access, Oracle, or MySQL) as indicated by your professor. After creating the database – populate it with some data (could be made up). SQL syntax and the DB application will be discussed and taught in class. This is the final deliverable of the group project. Assignment is due by the due date as indicated by your professor. *Make sure to submit the completed database...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT