In: Computer Science
Develop the SQL scripts that will create the tables and enforce all the appropriate
constraints
• Develop sample SQL scripts that will insert the data to the database (one row in each
table)
• Convert at least 2 entities to MongoDB Collections. Write the scripts that will Create the
collection(s)
consider a table containing records of a University:
Student | Student id | Subject | Faculty/Instructor |
Alex | 1 | Accountancy | Robert |
Bob | 2 | Numerology | Franklin |
Charlie | 3 | Anthropology | Albert |
David | 4 | Computer Science | Ronald |
To create this Table, the folloowing SQL statements are used:
CREATE TABLE records(Student varchar(20),Student-id number(10),Subject varchar(100),Faculty varchar((20))
Now, an empty table with Columns Student,Student-id,Subject,Faculty are created.
Then,to insert rows into the table with SQL queries, the following SQL statements are used:
INSERT into records(Student,Student-id,Subject,Faculty) values('Alex',1,'Accountancy','Robert');
INSERT into records(Student,Student-id,Subject,Faculty) values('Bob',2,'Numerology','Franklin');
INSERT into records(Student,Student-id,Subject,Faculty) values('Charlie',3,'Anthropology','Albert');
INSERT into records(Student,Student-id,Subject,Faculty) values('David',4,'Computer Science','Ronald');
TO Create Collections in MongoDB, we can use the following lines of code:
db.records.insertOne({ Student:"Alex",Student-id:1,Subject:"Accountancy",Faculty:"Robert"})
db.records.insertOne({ Student:"Bob",Student-id:2,Subject:"Numerology",Faculty:"Franlin"})
db.records.insertOne({ Student:"Charlie",Student-id:3,Subject:"Anthropology",Faculty:"Albert"})
db.records.insertOne({ Student:"David",Student-id:4,Subject:"Computer Science",Faculty:"Ronald"})
db.createCollections("records")