Professional Documents
Culture Documents
RDBMS Complete Practical
RDBMS Complete Practical
Moving on, you will look at how to install MySQL Workbench on Windows. The installation
process is similar to other operating systems.
1. Open the MySQL website on a browser. Click on the following link: MySQL Downloads.
6. It will ask for permission; when it does, click Yes. The installer will then open. Now, it will
ask to choose the setup type. Here, select Custom.
7. Click on Next. With this, you will install MySQL server, MySQL Workbench, and MySQL
shell.
8. Open MySQL Servers, select the server you want to install, and move it to
the Products/Features to be installed window section. Now, expand Applications, choose
MySQL Workbench and MySQL shell. Move both of them to ‘Products/Features to be
installed’.
9. Click on the Next button. Now, click on the Execute button to download and install the
MySQL server, MySQL Workbench, and the MySQL shell.
10. Once the product is ready to configure, click on Next. Under Type and Networking, go
with the default settings and select Next.
11. For authentication, use the recommended strong password encryption.
13. Go for the default windows service settings and under apply configuration, click on
execute. Once the configuration is complete, click on finish.
14. Complete the installation. This will now launch the MySQL Workbench and the MySQL
Shell.
Once MySQL Workbench is installed, select the Local instance and enter the password.
Now, you can use the MySQL query tab to write your SQL queries.
Store this backup file in a manner consistent with the data classification appropriate to your
site's content. Sites which store sensitive internal or critical data must be stored in secure
locations.
If you're using versions of Workbench before 6.3.8, including on IUanyWare, you will have an
unhandled exception when trying to export on the new system. You will be unable to export until
you update Workbench.
5. Under Export Options, select where you want your dump saved. By default, it will save to
your Documents folder in a subfolder titled dumps.
6. Click Start Export.
Note:
You may get a message about a mismatch between your mysqldump.exe version and the
MySQL Server version. You can update your local MySQL version or continue.
7. You now have a backup version of your site. Store this content securely in a manner consistent
with your MySQL schema content's data classification.
PRACTICAL 2
Create a simple database for Social Networking Platform with the
following entities
(i) Create tables with fields of appropriate data types:
(iii) To fetch all the users who are above 32 years old, we
can use the following SQL query:
SELECT * FROM users WHERE TIMESTAMPDIFF(YEAR, dob, CURDATE()) > 32;
(iv) To find the count of users who signed-up with a Gmail
ID, we can use the following SQL query:
SELECT COUNT(*) FROM users WHERE email LIKE '%@gmail.com';
- Grant all privileges to the user 'Staff ‘and grant only ‘create’privilege to
‘student’user and verify the same .
Grant all privileges to the user 'Staff’
Execute a 'SELECT' query and store its result in a user defined variable.
Use another ‘SELECT' to display the value of the variable
Practical-7
Create two tables with the following structure.
a) Requests table request_id - UNSIGNED, INT, AUTO INCREMENT,
PRIMARY KEY from_id - INTto_id – INT
create database prcatical_7;
CREATE TABLE requests (
request_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
from_id INT,
to_id INT
);
INSERT INTO requests (from_id, to_id)
VALUES (1, 2),
(3, 4),
(5, 6);
c) Create a view combining both tables to display all the requests along with
their most recent status for the requests.
CREATE VIEW requests_view AS
SELECT requests.request_id,from_id, to_id, request_status
FROM requests,requests_log
where requests.request_id = requests_log.request_id;
SELECT * FROM requests_view;
Practical-8
Create a library Table with proper fields.
CREATE TABLE library (
book_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
publication_year INT,
category VARCHAR(50)
);
Create another table called Library1 and insert rows from Library table.
Practical-9
Create a table to store the details of a customer in a Bank.
create database practical_9;
CREATE TABLE customer (
customer_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
account_number VARCHAR(20) NOT NULL,
credit_limit DECIMAL(10, 2) NOT NULL,
balance DECIMAL(10, 2) DEFAULT 0.00
);
Inserting Values
INSERT INTO customer (name, account_number, credit_limit, balance)
VALUES
('John Doe', '1234567890', 100000.00, 50000.00),
('Jane Smith', '9876543210', 50000.00, 25000.00),
('Mike Johnson', '5678901234', 200000.00, 150000.00);
select * from customer;
Find the Balance amount (Credit Limit). Based on customer’s credit limit, write
a program using IF or CASE flow control statements to find the customer levels
namely SILVER, GOLD or PLATINUM.
If the Credit limit is
• greater than 50K, then the customer level is PLATINUM
• less than 50K and greater than 10K, then the customer level is GOLD
• less than 10K, then the customer level is SILVER
SELECT
customer_id,
name,
account_number,
credit_limit,
balance,
IF(credit_limit > 50000, 'PLATINUM', IF(credit_limit > 10000, 'GOLD', 'SILVER')) AS
customer_level
FROM customer;
Practical-10
Create two tables with the following structure.
a) users - tablename user_id - UNSIGNED, INT, AUTO INCREMENT,
PRIMARYKEY username -VARCHAR (60) password - VARCHAR (128)
email- VARCHAR (255)
create database practical_10;
CREATE TABLE users (
user_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(60),
password VARCHAR(128),
email VARCHAR(255)
);
SELECT the users who do not have profiles (Hint: USE LEFT JOIN
and exclude the rows generated with NULL values from joining table)
SELECT u.user_id, u.username, u.email
FROM users u
LEFT JOIN users_profiles p
ON u.user_id = p.user_id
WHERE p.user_id
IS NULL;
Practical-11
Create an employee database and create a stored procedure that accepts
employee _Id as input and returns complete details of employee as output.
create database practical_11;
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
phone_number VARCHAR(20),
hire_date DATE,
job_title VARCHAR(100),
department VARCHAR(100)
);
//DELIMITER ;
CALL GetEmployeeDetails(2);