0% found this document useful (0 votes)
248 views

Course Ra

The document contains SQL queries to create a database called "roster" with three tables: "User", "Course", and "Member". The "User" table stores user names and IDs. The "Course" table stores course titles and IDs. The "Member" table stores the relationships between users and courses, including user IDs, course IDs, and user roles in each course. The document then populates the tables with sample data by inserting user names, course titles, and user-course memberships.

Uploaded by

AL Varun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
248 views

Course Ra

The document contains SQL queries to create a database called "roster" with three tables: "User", "Course", and "Member". The "User" table stores user names and IDs. The "Course" table stores course titles and IDs. The "Member" table stores the relationships between users and courses, including user IDs, course IDs, and user roles in each course. The document then populates the tables with sample data by inserting user names, course titles, and user-course memberships.

Uploaded by

AL Varun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Copy and paste these quaries 1 by 1 on xampp shell

DROP DATABASE IF EXISTS roster;

CREATE DATABASE roster;

USE roster;

DROP TABLE IF EXISTS Member;


DROP TABLE IF EXISTS `User`;
DROP TABLE IF EXISTS Course;

CREATE TABLE `User` (


user_id INTEGER NOT NULL AUTO_INCREMENT,
name VARCHAR(128) UNIQUE,
PRIMARY KEY(user_id)
) ENGINE=InnoDB CHARACTER SET=utf8;

CREATE TABLE Course (


course_id INTEGER NOT NULL AUTO_INCREMENT,
title VARCHAR(128),
PRIMARY KEY(course_id)
) ENGINE=InnoDB CHARACTER SET=utf8;

CREATE TABLE Member (


user_id INTEGER,
course_id INTEGER,
role INTEGER,

CONSTRAINT FOREIGN KEY (user_id) REFERENCES `User` (user_id)


ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (course_id) REFERENCES Course (course_id)
ON DELETE CASCADE ON UPDATE CASCADE,

PRIMARY KEY (user_id, course_id)


) ENGINE=InnoDB CHARACTER SET=utf8;

//change the below names as given for you on coursera page

INSERT INTO `user` (`user_id`, `name`) VALUES (NULL, 'Leigh'), (NULL, 'Declyan'),
(NULL, 'Gabriel'), (NULL, 'Ilsa'), (NULL, 'Leno'),
(NULL, 'Duncan'), (NULL, 'Ardal'), (NULL, 'Boni'), (NULL, 'Carragh'), (NULL,
'Indy'), (NULL, 'Seb'), (NULL, 'Adison'), (NULL, 'Arihant'),
(NULL, 'Jesutobiloba'), (NULL, 'Patrick');

SELECT * FROM `user` ORDER BY user_id ASC;

//Insert as it is

INSERT INTO `course` (`course_id`, `title`) VALUES (NULL, 'si106'), (NULL,


'si106'), (NULL, 'si106'), (NULL, 'si106'), (NULL, 'si106'),
(NULL, 'si110'), (NULL, 'si110'), (NULL, 'si110'), (NULL, 'si110'), (NULL,
'si110'), (NULL, 'si206'), (NULL, 'si206'), (NULL, 'si206'),
(NULL, 'si206'), (NULL, 'si206');

//Insert as it is

INSERT INTO `member` (`user_id`, `course_id`, `role`) VALUES ('1', '1', '1'), ('2',
'2', '0'), ('3', '3', '0'), ('4', '4', '0'),
('5', '5', '0'), ('6', '6', '1'), ('7', '7', '0'), ('8', '8', '0'), ('9', '9',
'0'), ('10', '10', '0'), ('11', '11', '1'),
('12', '12', '0'), ('13', '13', '0'), ('14', '14', '0'), ('15', '15', '0');

//refer coursera instruction page

You might also like