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

Dbms - Assignment 1 Sol

The document provides instructions for creating databases, users, and tables in MySQL and writing SQL queries. It includes: 1. Creating a 'dac' user and granting permissions to create databases and tables. 2. Creating an 'spj' database and granting 'dac' user permissions to access it. Instructions to create an 'S' table within 'spj'. 3. Creating a 'classwork' database, granting 'dac' permissions, and importing data from a SQL file. 4. Writing SELECT queries against sample 'employees' and 'hr' databases to return names, salaries, specific rows and columns, and aggregate functions. 5. Additional queries demonstrated against 'spj'

Uploaded by

bijdraagt
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views

Dbms - Assignment 1 Sol

The document provides instructions for creating databases, users, and tables in MySQL and writing SQL queries. It includes: 1. Creating a 'dac' user and granting permissions to create databases and tables. 2. Creating an 'spj' database and granting 'dac' user permissions to access it. Instructions to create an 'S' table within 'spj'. 3. Creating a 'classwork' database, granting 'dac' permissions, and importing data from a SQL file. 4. Writing SELECT queries against sample 'employees' and 'hr' databases to return names, salaries, specific rows and columns, and aggregate functions. 5. Additional queries demonstrated against 'spj'

Uploaded by

bijdraagt
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Database Technologies – Assignment 1

1. Create 'dac' user with password 'dac'.


ANS :
-CREATE USER 'dac'@'localhost' IDENTIFIED BY 'dac';

2. Create 'spj' database & grant all permissions to 'dac' user.


ANS :
-CREATE DATABASE spj;
-GRANT ALL PRIVILEGES ON *.* TO 'dac'@'localhost';
-SHOW GRANT FOR 'dac'@'localhost';

3.Create following tables in spj database (by 'dac' login).


ANS:
-CREAT TABLE S (`S#` CHAR(5) NOT NULL, Sname CHAR(20), Status SMALLINT,
City CHAR(15));
-DESC S
-INSERT INTO S VALUES ('S5','Adams',30,'Athens');
-SELECT * FROM S;
4.Create 'classwork' database & grant all permissions to 'dac'
user. Import classwork-db.sql.
ANS: -CREATE DATABASE classwork;
-GRANT ALL PRIVILEGES ON *.* TO 'dac'@'localhost';
-show databases;
-SHOW GRANTS FOR 'dac'@'localhost';
-use classwork;
-source /home/sunbeam/dbt/dbs/classwork-db.sql
-show tables;

SAME GOSE FOR Que 5-7.

Write the SELECT queries to do the following:-


Note : To solve below queries use “hr” database
1. Write a query to display the first_name, last_name using alias name “First Name", "Last
Name".
2. Write a query to get the names (first_name, last_name), salary, PF of all the employees (PF
is calculated as 15% of salary).
3. Write a query to select first 10 records from a employees table.

mysql> select * from employees limit 10;

4. Write a query to display job id and job title of first 5 jobs.


5. Write a query to display location id, street address and postal code of 6 locations after first
3 locations.

mysql> select * from employees limit 3,6;

6. Write a query to display job title and difference between max and min salary for that job.
mysql> select max(salary)-min(salary) AS DIFF from employees ;

Note : To solve below queries use “spj” database


1. Display all the data from the S table.
2. Display only the S# and SNAME fields from the S table.
3. Assuming that the Part Weight is in GRAMS, display the same in MILLIGRAMS and
KILOGRAMS.

mysql> select Weight*1000 GRAM, weight/1000 KILO from P;

Note : To solve below queries use “sales” database


1. What is the 4 th column of the Customers table?
2. What is another word for row? For column?
3. Why isn’t it possible to see the first five rows of a table?
4. Write a select command that produces the order number, amount,
and date forall rows in the Orders table.
5. Write a query that displays the Salespeople table with the
columns in the following order: city, sname, snum, comm.

You might also like