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

DB Lab 2

The document provides an overview of SQL concepts including database fundamentals, database design, SQL basics, data sorting, functions, and SQL syntax. Key topics covered include creating and manipulating tables, inserting and deleting rows, aggregation functions, joins, and normalization.

Uploaded by

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

DB Lab 2

The document provides an overview of SQL concepts including database fundamentals, database design, SQL basics, data sorting, functions, and SQL syntax. Key topics covered include creating and manipulating tables, inserting and deleting rows, aggregation functions, joins, and normalization.

Uploaded by

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

SECE Database System

Lab Manual PREPARED BY | YOHAN.R


SQL Syllabus

Database Fundamentals Must Know Stuff!


What is a Database? — Definition, Meaning, Types, Example IS NULL & IS NOT NULL — Learn with Example
What is SQL? — Learn SQL Basics, SQL Full Form & How to Use AUTO_INCREMENT — Learn with Example
ALTER, DROP, RENAME, MODIFY — What is, Syntax with Examples
Database Design KEYS — primary, foreign, composite…… keys
Database Design — Learn Data Modeling LIMIT & OFFSET — Learn with Example
What is Normalization? — 1NF, 2NF, 3NF, BCNF Database Example IMPOR AND EXPORT DB
What is ER Modeling? — Learn with Example
Most Dreaded Topics!
SQL Basics Subquery — Learn with Example
Create Table — How to Create Database in MySQL JOINS — INNER, OUTER, LEFT, RIGHT, CROSS
SELECT Statement — Learn with Example UNION — Complete Tutorial
WHERE Clause — AND, OR, IN, NOT IN Query Example Views — How to Create View from Tables with Examples
INSERT INTO Query — How to add Row in Table (Example) Index — Create, Add & Drop
DELETE Query — How to Delete Row from a Table Privilege — Grant and Revoke
MySQL UPDATE Query — Learn with Example

Data Sorting What Next!


ORDER BY in MySQL — DESC & ASC Query with Example 1. Requirement Analysis
GROUP BY and HAVING Clause — Learn with Example 2. Design the str of the DB
Wildcards — Like, NOT Like, Escape, ( % ), ( _ ) ⌂Your First Application using MySQL and PHP
Regular Expressions (REGEXP) — What is, Syntax and Examples

Functions
Functions — String, Numeric, User-Defined, Stored
Aggregate Functions — SUM, AVG, MAX, MIN , COUNT, DISTINCT

prepared by| YOHAN.R


DBL (Database Language)
Table Includes
TOPICS
1. Attributes
1. DBL
2. Data Type
2. Data Types
3. Size
3. Constraints
4. Constraints (unique,
4. Clauses Default,Pk,Fk,Null, Check)
5. Aggregate Functions
6. Wild cards and operators
7. View, Join and Union Database Objects
8. Normalization 1. Table
9. ER and Relational Model 2. Store Procedure
10. Index & Privilege 3. View (Virtual Table)
4. Function

SQL Is standard Language For Storing, Manipulating & Retrieving Data in DataBase.

The Most Basic SQL Commands


Basic Datatype ➢ Add
Database Tasks
➢ Drop
1. Numeric ➢ Table Alter 1. Create
Create ➢ Modify
2. Char – String 2. Insert/Add
3. Date & Time ➢ Count 3. View
➢ Data
4. Binary ➢ Rename
Insert/Add ➢ Row & Column Misc 4. Select
5. Spatial ➢ Alias
5. Drop/Delete
➢ From, Where & Distinct
6. Alter
➢ Database
➢ Table ➢ Order by, Group by & having 7. Misc
View Clauses
8. Clause
➢ And, or, Between
➢ Database and Table
➢ Is null & not null
Select ➢ Column and Raw Conditions ➢ Not equal

➢ Count, sum & Avg


➢ Database & Table
➢ Min & Max
Drop/Delete ➢ Column & Row Aggr’ Fun’n ➢ Concat

prepared by| YOHAN.R


SQL Syntax
➢ SHOW Database SHOW databases;

➢ USE Statement USE database_name;

➢ CREATE DATABASE CREATE DATABASE database_name;

➢ DROP DATABASE DROP DATABASE database_name;

➢ CREATE TABLE CREATE TABLE table_name(column1 datatype,column2 datatype,column3 datatype,.....


columnN datatype,PRIMARY KEY( one or more columns ));

➢ DROP TABLE DROP TABLE table_name;

➢ INSERT INTO INSERT INTO table_name( column1, column2....columnN) VALUES ( value1, value2....valueN);

➢ UPDATE Table UPDATE table_name SET column1 = value1, column2 = value2....


columnN=valueN[ WHERE CONDITION ];

➢ DELETE Row/Column DELETE FROM table_name WHERE {CONDITION};

➢ ALTER TABLE ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

➢ ALTER TABLE (Rename) ALTER TABLE table_name RENAME TO new_table_name;

➢ SELECT Statement SELECT column1, column2....columnN FROM table_name;

➢ DISTINCT Clause SELECT DISTINCT column1, column2....columnN FROM table_name;

➢ WHERE Clause SELECT column1, column2....columnN FROM table_name WHERE CONDITION;

prepared by| YOHAN.R


SQL Lab I - Tasks Summery

TASKS
1 Database and Table – Create & Insert.
2 Tables – Show, Rename & Truncate.
3 Row & Column – Select, Add, Delete(Drop), Alter and Update.
4 Misc – Distinct & Alias Name, Count, AVG, SUM.
5 Apply Specific Tasks – we will see some examples
6 Sorting – Order by (Asc & Desc), Group by.
7 Wild Card Cxs – Like %
8 Condition/Operators - (And, Or, Between)
9 Constraints – (Default, Unique, PK, Fk, Null & Check)
10 Bodmas Rule , Control Flow (if)
11 Table with PK and Fk
12 Join & Union
13 Miscellaneous
14 Relationship
15 Final Project

prepared by| YOHAN.R


Data Base
Show Databases;
Lab 1
Create Database Company; Let’s Create a Database =“Company” and Table = “Employee”
Use company;
show Tables;
Drop Company;

Table
1. Create Table Employee (
2. Insert Into Employee (
3. Select * From Employee;
4. Describe a Table Describe
(Field, Datatype and Constraint)
5. Describe Row / Column

1
Select a Column

1. select EmpName from employee;


2. select EmpName from employee
where salary > 45.000;

Select a Row
2
1. Select * from employee where EmpID ='3’;
2. update employee set Salary ='36.254’
where EmpName = 'Danilo ayzak';

add a Column and Row


>> alter table employee ADD Quality int;

Delete Row /Drop Column


>> delete from employee where EmpID = 6;
>> alter table student Drop column pro;
prepared by| YOHAN.R
Lab 1 SQL Query
1 5

4 8

prepared by| YOHAN.R


Lab 2
Let’s Create a Database =“ Company ” and Table = “ EmployeeX ” ,” EmployeeY ”

“ Employee_X ” “ Employee_Y ”

prepared by| YOHAN.R


Lab 2 SQL Query
+

prepared by| YOHAN.R


Lab 2.1 SQL Query

A wildcard character is used to substitute any other character(s) in a


string.
Wildcard characters are used with the SQL LIKE operator. The LIKE operator
is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards used in conjunction with the LIKE operator:
% - The percent sign represents zero, one, or multiple characters
_ - The underscore represents a single character.

prepared by| YOHAN.R


SQL Constraints
SQL Constraints
SQL constraints are used to specify rules for the data in a table.

Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the
table. If there is any violation between the constraint and the data action, the action is aborted.

Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the
whole table.

The following constraints are commonly used in SQL:

• NOT NULL - Ensures that a column cannot have a NULL value

• UNIQUE - Ensures that all values in a column are different

• PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table

• FOREIGN KEY - Prevents actions that would destroy links between tables

• CHECK - Ensures that the values in a column satisfies a specific condition

• DEFAULT - Sets a default value for a column if no value is specified

• CREATE INDEX - Used to create and retrieve data from the database very quickly

prepared by| YOHAN.R


SQL Lab II - Tasks Summery

TASKS
1 Join and Union
2 View, Index
3 Normalization
4 Relationship
5
6

prepared by| YOHAN.R


Lab 3
6
1| /*..... SORTING METHOD ....*/ 2| /*..... JOIN ....*/ Database Name - OFFICERS
Officer Student
s

|ORDERED BY |
(Asc)

| GROUP BY |
7
3| /*..... UNION ....*/ Database Name - SCHOOL
ORDERED BY |
(Desc) CS SECE

HAVING |

Rename and Truncate Table


Upcoming Lab Tasks

STUDENT MANAGEMENT SYSTEM

o Identify Problems- what we need to Do?


o Define Tables\
o Specify Databases
o Normalize tables
o Specify Keys
o Define Relationships
o Draw ER Diagrams
o Start coding

prepared by| YOHAN.R


Sequential Query Language

THANK YOU!!
DBMS Lab Cheat sheet by Yohannes R.

SECE Database System Student Version


Lab Manual PREPARED as| Intermediate Level

You might also like