MySQL

                                             MySQL 

                                                       Topic 1:-SQL STATEMENTS

Throughout our SQL programming session, we will be taking an example of the most popular database of ALUMNI MANAGEMENT SYSTEM

Alumni Management System

Refer the ER Diagram for Alumni Management System.
Create the following tables and write queries for the following DDL operations.

1:-DDL STATEMENTS-CREATE/ALTER/DROP
DDL-Data Definition Language
1.1 Create table role
Write a query to create role table. Sample Query: create table role (id BIGINT(20), name varchar(255) NOT NULL, primary key(id)); 
QUERY 1.1: 
1  create table role
2(
3  id bigint(20),
4  name varchar(255) not null,
5  primary key(id));
1.2 Create table skill
1create table skill(
2id BIGINT(20) NOT NULL,
3description VARCHAR(255),
4name VARCHAR(255) not null,
5primary key(id));
1.3 Create table post_type
1create table post_type(
2id bigint(20) not null,
3name varchar(255) not null,
4primary key(id));
1.4 Create table department
1create table department(
2id bigint(20) not null,
3name varchar(255) not null,
4primary key(id));
1.5 Create table degree
1create table degree(
2id bigint(20) not null,
3department_id bigint(20) not null,
4name varchar(255) not null,
5primary key(id),
6foreign key(department_id) references department(id));

1.6 Create table profile
1create table profile(
2id bigint(20) not null,
3address varchar(255) not null,
4batch varchar(255) not null,
5degree_id bigint(20) not null,
6designation varchar(255),
7gender varchar(255) not null,
8primary key(id),
9foreign key(degree_id) references degree(id));

1.7 Create table higher_degree
1create table higher_degree(
2id bigint(20) not null,
3degree_name varchar(255),
4university_name varchar(255),
5profile_id bigint(20) not null,
6primary key(id),
7foreign key(profile_id) references profile(id));

1.8 Create table experience


1create table experience(
2id bigint(20) not null,
3company_name varchar(255) not null,
4current bit(1) not null,
5end datetime,
6start datetime not null,
7profile_id bigint(20) not null,
8primary key(id),
9foreign key (profile_id) references profile(id));
1.9 Create table project
1create table project(
2id bigint(20) not null,
3name varchar(255) not null,
4number_of_members int(11) not null,
5profile_id bigint(20) not null,
6short_description varchar(255),
7primary key(id),
8foreign key(profile_id) references profile(id));
1.10 Create table profile_skills
1create table profile_skills(
2skill_id bigint(20) not null,
3profile_id bigint(20) not null,
4constraint primary key(skill_id,profile_id),
5foreign key(skill_id) references skill(id),
6foreign key(profile_id) references profile(id));
1.11 Create table user
01create table user(
02id bigint(20) not null,
03emailid varchar(255) not null,
04name varchar(255) not null,
05password varchar(255) not null,
06phonenumber varchar(255) not null,
07profile_id bigint(20),
08role_id bigint(20) not null,
09username varchar(255) not null,
10primary key(id),
11foreign key(role_id) references role(id));
1.12 Create table query
1create table query(
2id bigint(20) not null,
3content varchar(255) not null,
4date datetime not null,
5parent_id bigint(20),
6user_id bigint(20) not null,
7primary key(id),
8foreign key(parent_id) references query(id),
9foreign key(user_id) references user(id));
1.13 Create table event


1create table event(
2id bigint(20) not null,
3date datetime not null,
4description varchar(255),
5invitation varchar(255) not null,
6name varchar(255) not null,
7organiser_id bigint(20) not null,
8primary key(id),
9foreign key(organiser_id) references user(id));
1.14 Create table post
1create table post(
2id bigint(20) not null,
3content varchar(255) not null,
4date datetime not null,
5type_id bigint(20) not null,
6user_id bigint(20) not null,
7primary key(id),
8foreign key (type_id) references post_type(id),
9foreign key (user_id) references user(id));
1.15 Add column to role  table 
1  alter table role
2add description varchar(255);
1.16 Change column type in role table 
1  alter table role
2modify column description varchar(500);
1.17 Remove column from role table 
1  alter table role
2drop column description;
1.18 Change table name role 
1  alter table role
2rename roles;
1.19 Change table name roles 
1  alter table roles
2rename role;
1.20 Add column to department table
  alter table department
add user_id bigint(20) not null;
1.21 Add foreign key constraint to department table 
  alter table department
add constraint foreign key(user_id) references user(id);
1.22 Remove column from table department 
  alter table department
drop column user_id;
1.23 Change table name department
  alter table department
rename departments;
1.24 Delete table from profile_skills
drop table profile_skills;
1.25 Delete table post

drop table post;