You are on page 1of 23

KAMAL INSTITUTE OF HIGHER EDUCATION AND

ADVANCE TECHNOLOGY
LAB FILE

Information System Management

Submitted to: Submitted by:

Ms Heena Bhalla Rudra Singh


BBA 2nd YEAR
Enrol. No.
02096717199
INDEX
S.No. Topics Signature Remark
1 Introduction to database management
system.
2 Introduction to structure query language.
3 To illustrate data definition language
commands in RDBMS.
4 To illustrate data manipulation language
command in RDBMS
5 To illustrate create table command in
SQL.
6 To illustrate insert values command in
SQL.
7 To illustrate describe command in SQL
8 To illustrate select table command in
SQL.
9 To illustrate update table command in
SQL.
10 To illustrate alter command in SQL.
11 To illustrate delete command in SQL.
12 To illustrate drop table command in
SQL.
13 To illustrate difference between delete &
drop table command in SQL.
14 To illustrate rename command in SQL.
15 To illustrate integrity constraint in SQL.

16 To illustrate relational model in DBMS

17 To illustrate Aggregate Functions in


SQL.
18 To illustrate Logical operator in SQL.
19 To illustrate Comparison operator in
SQL
20 To illustrate join command in SQL.
Introduction to Database
Management System.
A database management system (DBMS) is a software package designed to define,
manipulate, retrieve and manage data in a database. A DBMS generally manipulates
the data itself, the data format, field names, record structure and file structure. It also
defines rules to validate and manipulate this data. 

A DBMS relieves users of framing programs for data maintenance. Fourth-generation


query languages, such as SQL, are used along with the DBMS package to interact
with a database.

Some other DBMS examples include:

 MySQL

 SQL Server

 Oracle

 dBASE

 FoxPro
Structure Query Language
SQL Introduction
SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel
– (Structured English Query Language)”.
It is a query language used for accessing and modifying information in the database. IBM
first developed SQL in 1970s. Also it is an ANSI/ISO standard. It has become a Standard
Universal Language used by most of the relational database management systems
(RDBMS).
Some of the RDBMS systems are: Oracle, Microsoft SQL server, Sybase etc. Most of
these have provided their own implementation thus enhancing its feature and making it a
powerful tool.
Few of the SQL commands used in SQL programming are SELECT Statement, UPDATE
Statement, INSERT INTO Statement, DELETE Statement, WHERE Clause, ORDER BY
Clause,.
In a simple manner, SQL is a non-procedural, English-like language that processes data in
groups of records rather than one record at a time. Few functions of SQL are:
 Store data
 modify data
 retrieve data
 modify data
 delete data
 create tables and other database objects
 delete data

Types of SQL statements


There are three basic types of SQL statements:
 Data definition language (DDL) statements
 Data manipulation language (DML) statements
 Data Control Language (DCL) statements

WHY SQL?

SQL is widely popular because it offers the following advantages-


 Allows users to access data in the relational database management systems.
 Allows users to describe the data.
 Allows users to define the data in a database and manipulate the data.
 Allows embedding within other language using SQL modules, libraries and pre-
compilers.
 Allows users to create and drop database and tablets.
 Allows users to create view, stored procedure and functions in a database.

USE OF SQL

1. Database Transaction Management:


Transaction Management means to maintain the transaction related to the database i.e.
following the basic rules for ACID properties of the database. The transaction has only two
results i.e. either success or failure. Thus the SQL Statement is TRANSACTION, COMMIT,
ROLLBACK and SAVE POINT.
1. Procedures, User-defined Functions, Triggers, Indexes, and others:
We can write procedures, user-defined functions, triggers, indexes, cursors as per the
requirements which are nothing but SQL statements to make our work easy to meet the
business requirements.
2. Reporting Purpose:
SQL queries are very important from a report perspective which every project has. We can
write queries for standalone reports also for fetching data for the report.
3. Manual Analysis:
SQL queries are very important for analysis when manual interventions are necessary. With
the uses of SQL queries we can filter out the necessary data from the structured data and it
could be used for analysis.
4. SQL with NTC Hosting:
Even the MySQL hosting service provides the ability for the construction of big and
powerful websites, web-based applications and programs. MySQL open source database
solution and insist on speed, stability and scalability, and then MySQL hosting solution is
needed.
5. SQL Join:
A SQL join is an instruction to combine data from two sets of data (i.e. two or more tables).
 (INNER) JOIN: Returns matching values in both tables as output.
 LEFT (OUTER) JOIN: It returns all records of the left table and the matching records
of the right table as output.
 RIGHT (OUTER) JOIN: It returns all records 0f the right table, and the matching
records of the left table as output.
 FULL (OUTER) JOIN: It returns all records if there is a match in either of the table i.e.
left or right
DATA TYPES OF SQL

1. CHAR: This data type is used to store character strings values of fixed length. The size in
brackets determines the number of characters the cell can hold. The maximum number of
characters (i.e. the size) this data type can hold is 255 characters.
Syntax: CHAR (SIZE)
Example: CHAR (20)

2. VARCHAR: This data type is used to store variable length alphanumeric data. The
maximum this data type can hold is 4000 characters. One difference between this data type
and the CHAR data type is ORACLE compares VARCHAR values using non-padded
comparison semantics i.e. the inserted values will not be padded with spaces.
Syntax: VARCHAR (SIZE)
Example: VARCHAR (20) OR VARCHAR2 (20)

3. NUMBER: The NUMBER data type is used to store numbers (fixed or floating point).
Syntax: NUMBER (P, S)
Example: NUMBER (10, 2)

4. DATE: This data type is used to represent data and time. The standard format id DD-MM-
YY as in 13-Jul-15. To enter dates other than the standard format, use the appropriate
functions. Date Time stores date in the 24-hour format. By default, the time in a date field is
12:00:00 am, if no time portion is specified. The default date for a date field is the first day of
the current month.

Syntax: DATE
Create Database
To create a New Database, we use the SQL CREATE DATABASE statement.
Syntax:
CREATE DATABASE<Database name>;

Example: CREATE DATABASE employees;

Use Database
To use database, we use the SQL USE ‘Database name’ stamen
Syntax:
USE<DATABASE>;

Example: USE employees;

Create a Table
To create a new table within a database, we use the SQL CREATE TABLE statement
Syntax:
CREATE TABLE <table name>
(
<Table element>,
<Table element>);

Example: Create Table employee ( employeename varchar(100), Employee_id int(100));

Insert value in table


INSERT INTO `table name` is the command to add new row into a table

Syntax:

Insert into <table_name> values (‘<value>’, <value>…);

Example: INSERT INTO employee Value (‘Divyanshu’, 03);

Retrieving Data from Table


DESCRIBE                                                                    

SQL DESC statement use for describe the list of column definitions for the specified table.
And it is used to describe a whole specified table.

DESCRIBE statement to get following information:


▪ Column Name
▪ Column allow NULL or NOT NULL
▪ Data type of the Column
▪ With database size precision and If 
NUMERIC data type scale.

SYNTAX:
DESC table name ;

SQL SELECT
Statement is used to view data from the table. This statement returns a list of table format
table data. Select return the data list from table with format. We use asterisk (*) sign to fetch
all table columns instead of writing all column names.

Syntax:
Select * from <table name>;
Retrieve some specific data.
Select <table element > from <table name> where <condition>

Example: Select * from employee;

Updating the content of table:


The update command is used to change or modify data values in a table. The verb UPDATE
in SQL is used to either all the rows from a table or a selected set of rows from a table.

Example: update table name SET field1= new value1, field2=new-value2;


(Where clause)
ALTER
SQL ALTER TABLE Statement to rename table name, add new column, modify existing
column (data type, size, etc.), drop the table column. SQL ALTER TABLE statement is a
powerful statement to add, manage or update table structure.

SYNTAX:

Alter table table_name, add(new column name);

Example: Alter table employee add (state varchar (100));

Delete
My SQL DELETE statement is used to delete data from the My SQL table within the
database. By using delete statement, we can delete records on the basis of conditions.

SYNTAX:

DELETE FROM table name, where column name = value;

Example: DELETE from employee where employee_id=03;


Drop
SQL DROP DATABASE, TABLE statement to drop the existing database.

SYNTAX: 

DROP TABLE table_name;

Example: DROP database leaf;


SQL Constraints
Constraints are used to limit the type of data that can go into a table.
Constraints can be specified when a table is created (with the CREATE TABLE statement) or
after the table is created (with the ALTER TABLE statement).
We will focus on the following constraints:
 NOT NULL
 PRIMARY KEY
 FOREIGN KEY

 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.

 SQL PRIMARY KEY Constraint

SQL PRIMARY KEY Constraint applies on column(s) for uniquely identifies each record
(row) in the table.
SQL Primary Key constraint has been specified for certain column. We cannot enter
duplicate data in this column.
SQL Primary Key in a table has following three special attributes,

▪ The NOT NULL attribute is automatic active.


▪ the data across the column must be unique.
▪ Defines column as a mandatory column.

After inserting values


 SQL FOREIGN KEY Constraint

Constraint apply on column(s) for whose value must have reference in another table
column (that existing column must be primary key or unique key constraint).SQL
FOREIGN KEY constraints also known as relationship (referential) constraints
 SYNTAX:  Foreign key (table2 Column name) references table (column name)

After inserting value in student info

Aggregate functions in SQL


SQL is excellent at aggregating data the way we might in a pivot table in Excel. We will use
aggregate functions all the time, so it's important to get comfortable with them. The functions
themselves are the same ones you will find in Excel or any other analytics program.

VARIOUS AGGREGATE FUNCTIONS:


 Count( )
 Sum( )
 Avg( )
 Min( )
 Max( )
 First ( )
 Last ( )

COUNT:
Counts how many rows are in a particular column.

SYNTAX:
Select count (column name) from table name;

SUM:
Adds together all the values in a particular column.

SYNTAX:
Select sum (column name) as expression from table name;
AVG:
Calculates the average of a group of selected values.

SYNTAX:
Select avg (column name) as expression from table name;

MIN:
Return the lowest values in a particular column, respectively.

SYNTAX:
Select min (column name) from table name;

MAX:
Return the lowest and highest values in a particular column, respectively.

SYNTAX:
Select max (column name) from table name;

 FIRST:

SYNTAX: 
 Select column name from table name limit1;
 LAST:

SYNTAX:
Select column name from table name order by column name desc limit 1;

LOGICAL OPERATOR:

VARIOUS TYPES OF LOGICAL OPERATOR


 Like
 Between
 And
 Or
 In

LIKE

SQL LIKE operator is used with WHERE clause to matches specific pattern in a column.
SQL LIKE condition applies on table column data.
Following two wildcards are often used with the LIKE operator

▪ % - Represents zero, or any number of characters


▪ _ - Represents a single character
  
SYNTAX:
Select* from table name where column name like value;
BETWEEN

SQL BETWEEN operator used for fetching within range data. SQL BETWEEN query is
simply a shorthand way of expressing an inclusive range comparison.

SYNTAX:
Select*from table name where column name between value and value;

AND
SQL AND condition use to test more than one conditions INSERT, UPDATE, DELETE,
SELECT statement. AND operator work is test first condition if true come to a second and so
forth, otherwise not check
Next condition.

SYNTAX:
Select* from table name where column name condition value and column name condition
value ;)
OR

SQL OR Condition use to test more than one conditions in INSERT, UPDATE, DELETE,
SELECT statement. OR operator test all condition even if condition TRUE or FALSE. And
return data when
any one of the condition TRUE. SQL OR Operator same as AND operator, return the record
base filtered data. INSERT, UPDATE, DELETE, SELECT statement perform only one of the
specified
Condition TRUE.

SYNTAX:
(Select * from table name where column name condition value or column name condition
value ;)

IN

The My SQL IN condition is used to reduce the use of multiple OR conditions in a SELECT,
INSERT, UPDATE and DELETE statement

SYNTAX:
Select * from table name where column name in {values};
COMPARISON OPERATION
A comparison (or relational) operator is a mathematical symbol which is used to compare
two values.
 Greater than 
 Less than
 Greater than equal to
 Less than equal to
 Equal to
 Not equal to

OPERATOR DESCRIPTION OPERATES ON


= Equals to Any compatible data type
> Greater than Any compatible data type
< Less than Any compatible data type
>= Greater than equal to Any compatible data type
<= Less than equal to Any compatible data type
<> Not equal to Any compatible data type

EQUALS TO:
SYNTAX:
SELECT * FROM table name WHERE column name = value;
GREATER THAN:
SYNTAX:
SELECT * FROM table name WHERE column name > value;

LESS THAN:
SYNTAX:
SELECT * FROM table name WHERE column name < value;

GREATER THAN EQAULS TO:


SYNTAX:
SELECT * FROM table name WHERE column name >= value;
LESS THAN EQUALS TO:
SYNTAX:
SELECT * FROM table name WHERE column name <= value;

NOT EQUAL TO:


SYNTAX:
SELECT * FROM table name WHERE column name <> value;
JOIN
My SQL JOINS are used with SELECT statements. It is used to retrieve data from multiple
tables. It is performed whenever you need to fetch records from two or more tables.
There are three types of My SQL joins:
 My SQL INNER JOIN (or sometimes called simple join)
 My SQL LEFT OUTER JOIN (or sometimes called LEFT JOIN)
 My SQL RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)

Inner join:

Left outer join:


Right outer join:

You might also like