Sei sulla pagina 1di 28

AMBEDKAR INSTITUTE OF TECHNOLOGY

SHAKARPUR, DELHI-110092
Govt. of NCT of Delhi,

Dept. Of training & Technical Education

DBMS PRACTICAL
FILE

Submitted to:- Submitted by:-


MANOJ SIR Name:- ANANY DEEP
Roll No.:-(0212)4818118
Dept.:- B.VOC(Software
Development)
Semester:-3rd Semester
Program no. Name of Program Date Signature
1. Write a query to represent SHOW and SELECT 05-AUG-2019
statement.
2. Write a query to represent use of DISTINCT and 12-AUG-2019
LIMIT.
3. Write a query to represent Basic Data Filtering 19-AUG-2019
and WHERE.
4. Advanced Filtering Using AND and OR 19-AUG-2019
statement.
5. Write a query to represent use of IN. 26-AUG-2019

6. Write a query to represent use of % sign. 02-SEPT-2019

7. Write a query to represent use of Regular 09-SEPT-2019


Expressions.
8. Write a query to represent Creating Custom 16-SEPT-2019
Columns.
9. Write a query to represent Functions. 23-SEPT-2019

10. Write a query to represent GROUP BY. 30-SEPT-2019

11. Write a query to represent Sub queries. 07-OCT-2019

12. Write a query to represent How to Join Tables. 14-OCT-2019

13. Write a query to represent use of UNION. 21-OCT-2019

14. Write a query to represent Full-Text Searching. 28-OCT-2019

15. Write a query to represent Inserting multiple rows 04-NOV-2019


in table.
16. Write a query to represent CREATE, UPDATE & 04-NOV-2019
DELETE.
17. Write a query to represent NOT NULL & AUTO 11-NOV-2019
INCREMENT.
18. Write a query to represent ALTER - DROP - 11-NOV-2019
RENAME TABLE.
DATABASE SCHEMA DETAILS
Platform: WampServer refers to a software stack for the Microsoft Windows operating system,
created by Romain Bourdon and consisting of the Apache web server, Open SSL for SSL
support, MySQL database and PHP programming language.
Database Structure
Table name-> CUSTOMERS
Attributes: - id –Primary key, name, address, city, state, zip

Database Structure
Table name -> ITEMS
Attributes: - id – Primary key, name, cost, seller, id, bids
CUSTOMERS TABLE DATA RECORDS
ITEMS TABLE DATA RECORDS
PRACTICAL-1

Aim: - Introduction to SHOW and SELECT statement.


Theory: - The SHOW statement is a flexible way to get information about different types of
Impala objects.

The SELECT statement is used to select data from a database. The result is stored in a result table,
called the result-set.

Query: - SHOW COLUMNS FROM customers;


OUTPUT
Query: - SELECT city FROM customers;
OUTPUT

Query: - SELECT * FROM customers;


OUTPUT
PRACTICAL-2
Aim: - In order to get unique or distinct result.
Theory: - In order to get unique or distinct result than we use DISTINCT in the command after
select.
SQL is structured query language which is a computer language for storing, manipulating and
retrieving data stored in relational databases.
Query: - SELECT id, name FROM customers LIMIT 5;

OUTPUT
PRACTICAL -3

Aim: - Basic Data Filtering and Use of WHERE.


Theory: - The WHERE clause is used to extract only those records that fulfill a specified criterion.
If the given condition is satisfied then only it returns specific value from the table. You would use
WHERE clause to filter the records and fetching only necessary records.
Query: - SELECT id, name FROM customers WHERE id<=8;
OUTPUT
PRACTICAL-4

Aim: - Advanced Filtering Using AND and OR STATEMENT.

Theory: - The AND & OR operators are used to filter records based on more than one condition.
The AND operator displays a record if both the first condition AND the second condition are true.
The OR operator displays a record if either the first condition OR the second condition is true.

Query: - SELECT name, state, city FROM customers WHERE state='CA' AND city =
‘Riverside’;
OUTPUT
PRACTICAL-5

Aim: - USE OF IN STATEMENT.


Theory: - Instead of using a bunch of OR statements we can use IN statement. This will reduce
our command line and will be less complicated.
Query: - SELECT name, state, FROM customers WHERE state IN (‘CA’,’NC’,’NY’);
OUTPUT
PRACTICAL-6
Aim: - Use of % sign.
Theory: - The % sign help us to make our search easier.

Ex: new% - this will search everything that starts with new.
Query: - SELECT city FROM customers WHERE city LIKE ‘h%d’;

OUTPUT
PRACTICAL-7

Aim: - Use of regular expressions


Theory: - MySQL pattern matching with LIKE ...%. MySQL supports another type of pattern
matching operation based on regular expressions and the REGEXP operator.
Query: - SELECT name FROM items WHERE name LIKE’% boxes of frogs';
OUTPUT

Query: - SELECT name FROM items WHERE name REGEXP'[3748]boxes of frogs';

OUTPUT
PRACTICAL-8

Aim: - Creating Custom Columns.


Theory: - Database is collection of related data and data is collection of facts and figures that can
be processed to produce the information. SQL is structured query language which is a computer
language for storing, manipulating and retrieving data stored in relational databases.
Query: - SELECT CONCAT (city, ’ , ’state) FROM customers;
OUTPUT

Query: - SELECT CONCAT (city, ’ ,’state) AS new_address FROM customers;


OUTPUT
PRACTICAL-9

Aim: - Functions
Theory: - count, sum, avg, max, min and list it doesn’t handle NULL in the same way as
ordinary function and operation instead of returning NULL operations is encountered, they only
take non- null fields into consideration while computing the outcome.
Query: - SELECT COUNT (*) AS item_count, MAX(cost) AS max, AVG(cost) AS avg FROM
items WHERE seller_id=12;

OUTPUT
PRACTICAL-10
Aim: - To Use Group by Function
Theory: - Group by clause is used in collaboration with SELECT statement to arrange identical
data in groups.
Query: - SELECT seller_id, COUNT (*) AS item_count FROM item GROUP BY seller id;
OUTPUT
PRACTICAL-11

Aim: - How to write Sub queries.


Theory: - Sub query is a query in a query. SQL sub query is usually added in the WHERE
Clause of the SQL statement. Most of the time, a sub query is used when you know how to
search for a value using a SELECT statement, but do not know the exact value in the database.
Query: - SELECT name, cost FROM items WHERE cost> (SELECT AVG (cost) FROM
items) ORDER BY cost DESC;

OUTPUT

Query: - SELECT name, MIN (cost) FROM items WHERE name LIKE ‘%boxes of frogs’
AND seller_id IN (SELECT seller_id FROM items WHERE name LIKE ‘%boxes of frogs’);

OUTPUT
PRACTICAL-12

Aim: - How to join tables.


Theory: - A SQL join is a Structured Query Language (SQL) instruction to combine data from
two sets of data (e.g. two tables). If we wanted to simply append information about orders to our
customers table, regardless of whether a customer placed an order or not, we would use a left join.
A left join returns all records from table A and any matching records from table B.
Query: - SELECT customers.id, customers.name, items.name, items.seller_id FROM
customers, items WHERE customers.id = items.seller_id ORDER BY customer.id;

OUTPUT
Query: - SELECT customers.name, items.name FROM customers LEFT OUTER JOIN
items ON customers.id = items.seller_id;

OUTPUT
PRACTICAL-13
Aim: - Use of UNION.
Theory: - Database is collection of related data and data is collection of facts and figures that can
be processed to produce the information.
SQL is structured query language which is a computer language for storing, manipulating and
retrieving data stored in relational databases.
Query: - SELECT name, cost, bids FROM items WHERE bids > 190;

OUTPUT
PRACTICAL-14

Aim: - FULL TEXT SEARCHING.


Theory: - Database is collection of related data and data is collection of facts and figures that can
be processed to produce the information.
SQL is structured query language which is a computer language for storing, manipulating and
retrieving data stored in relational databases.
Query: - ALTER TABLE items ADD FULLTEXT (name);

OUTPUT

Query: - SELECT name, cost FROM items WHERE MATCH (name) Against (‘baby’);
OUTPUT

Query: - SELECT name, cost FROM items WHERE MATCH (name) against
(‘+baby_coat’ IN boolean MODE);
OUTPUT
PRACTICAL-15

Aim: - Inserting multiple rows in table.


Theory: - Data manipulation language is used to edit the database.
To edit the database, INSERT, UPDATE AND DELETE command is used.
Query: - INSERT INTO ITEMS (id, name, cost, seller_id, bids) VALUES (‘102’, ‘FISH N
CHIPS’, ‘8’, ‘63’, ‘20’);

OUTPUT

Query: - INSERT INTO ITEMS (id, name, cost, seller_id, bids) VALUES (‘1095’, ‘FISH N
CHOPS’, ‘8’, ‘63’, ‘20’), (‘1058’, ‘PASTRY’, ‘9’, ‘64’, ‘2’), (‘1049’, ‘COLD DRINK’, ‘2’, ‘5’,
‘8’);
OUTPUT
PRACTICAL-16

Aim: - CREATE UPDATE AND DELETE.


Theory: - Database is collection of related data and data is collection of facts and figures that can
be processed to produce the information.
SQL is structured query language which is a computer language for storing, manipulating and
retrieving data stored in relational databases.

Query: - UPDATE items SET name='beam' WHERE id=106;


OUTPUT

Query: - DELETE FROM items WHERE id=106;


OUTPUT

Query: - CREATE TABLE users (id int, username varchar(30), password varchar(20)
PRIMARY KEY(id));

OUTPUT
PRACTICAL-17

Aim: - NOT NULL & AUTO INCREMENT


Theory: - SQL NOT NULL constraint: - The NOT NULL constraint enforces a column to NOT
accept NULL values. The NOT NULL constraint enforces a field to always contain a value. This
means that you cannot insert a new record, or update a record without adding a value to this field.
AUTO INCREMENT
Very often we would like the value of the primary key field to be created automatically every
time a new record is inserted. We would like to create an auto-increment field in a table.
Query: - CREATE TABLE bacon (id int NOT NULL AUTO_INCREMENT, username
varchar(30) NOT NULL, password varchar(30) NOT NULL, PRIMARY KET(id));

OUTPUT
PRACTICAL-18

Aim: - Alter, Drop and Rename table


Theory: - ALTER Statement
The SQL ALTER statement is used to modify database objects, specifically tables. Altering table
elements can include adding and dropping columns, changing column definitions, adding and
dropping constraints, modifying table storage values and more.
DROP Statement
The DROP TABLE statement is used to delete tables that you do not need anymore. Once this line
is executed, all the data and metadata contained in the table are also removed. DROP TABLE is
considered to be the easiest command to execute. However, an error will occur if the table to be
deleted is being referenced by another table in the database. That is why you need to be cautious
when performing the DROP statement to avoid deleting objects by mistake.
Query: - ALTER TABLE bacon DROP COLUMN samplecolumn;

OUTPUT

Potrebbero piacerti anche