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

useless

Uploaded by

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

useless

Uploaded by

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

1

MYSQL – SQL

DATABASE CONCEPTS:

• A database management system (DBMS) or database system in short, is a


software that can be used to create and manage database
• DBMS allows to create a database, store, manage, update/modify and
retrieve data from that database by users or application programs
• Examples of open source and commercial DBMS include MySQL, Oracle,
PostgreSQL, SQL Server, Microsoft Access, MongoDB.
• The DBMS serves as an interface between the database and end users or
application programs
• Real life applications of DBMS : Banking system, Inventory Management,
Organization resource management, Online shopping etc.

SQL: Structured Query Language is a unified, non procedural language used for creating,accessing
handling and managing data in relational databases.

Features of SQL:
1. Retrieve data from database through Query processing.
2. Insert records into database
3. Update records into database
4. Create new and modify
5. Create new tables
6. Create views
7. Allow modify security settings

Advantages of SQL
1. Ease of Use
2. Large Volume of data
3. No coding required
4. High Level Languages
5. Portable
6. Not a Case sensitive language
7. Powerful Language
8. Reliable
9. Freedom of data abstraction
10. Complete Language for a database
2

Classification of SQL statements

KEY CONCEPTS IN DBMS:

• Database Schema : It is the skeleton of the database that represents the


structure, the type of data each column can hold, constraints on the data
to be stored (if any), and the relationships among the tables.
• Data Constraint : Sometimes we put certain restrictions or limitations on
the type of data that can be inserted in one or more columns of a table.
This is done by specifying one or more constraints on that column(s) while
creating the tables. Eg: Not Null, Unique etc.
• Meta-data or Data Dictionary : The database schema along with various
constraints on the data is stored by DBMS in a database catalog or
dictionary, called meta-data. A meta-data is data about the data
• Database Instance : loading data, the state or snapshot of the database
at any given time is the database instance, data can be accessed through
it
• Query : A query is a request to a database for obtaining information in a
desired way
• Data Manipulation : Modification of database consists of three operations
viz. Insertion, Deletion or Update
• Database Engine : Database engine is the underlying component or set
of programs used by a DBMS to create database and handle various queries
for data retrieval and manipulation
3

RELATIONAL DATA MODEL:

• A data model describes the structure of the database, including how data
are defined and represented, relationships among data, and the
constraints. The most commonly used data model is Relational Data ModeL
• In relational model, tables are called relations that store data for different
columns. Each table can have multiple columns where each column name
should be unique. For example, each row in the table represents a related
set of values
❖ Attribute : columns of a relation
❖ Tuple : rows of a relation
❖ Domain : It is a set of values from which an attribute can take a value in
each row
❖ Degree : The number of attributes in a relation is called the Degree of the
relation
❖ Cardinality : The number of tuples in a relation is called the Cardinality of
the relation

KEYS IN A RELATIONAL DATABASE:

❖ Candidate Key : A relation can have one or more attributes that takes
distinct values. Any of these attributes can be used to uniquely identify the
tuples in the relation. Such attributes are called candidate keys as each of
them are candidates for the primary key

❖ Primary Key : the attribute chosen by the database designer to uniquely


identify the tuples in a relation is called the primary key of that relation

❖ Alternate Key: All remaining candidate keys is known as alternate key

❖ Foreign Key: A foreign key is used to represent the relationship between


two relations. A foreign key is an attribute whose value is derived from the
primary key of another relation

NOTE : There are many RDBMS such as MySQL, Microsoft SQL Server,
PostgreSQL, Oracle, etc.
4

STRUCTURED QUERY LANGUAGE (SQL):

❖ is the most popular query language used by major relational database


management systems such as MySQL, ORACLE, SQL Server,
❖ SQL Rules:
➢ SQL is case insensitive. That means name and NAME are same for
SQL.
➢ Always end SQL statements with a semicolon (;).

DATA TYPE OF ATTRIBUTE:

➢ Data type indicates the type of data value that an attribute can have and
the operations that can be performed on the data of that attribute

VARCHAR • Variable length


• declaring VARCHAR (30) means a maximum of 30
characters can be stored but the actual allocated bytes
will depend on the length of entered string
INT Integer value. Each INT value occupies 4 bytes of storage

FLOAT Holds numbers with decimal points. Each FLOAT value occupies
4 bytes.
DATE The DATE type is used for dates in 'YYYY-MM-DD' format. YYYY
is the 4 digit year, MM is the 2 digit month and DD is the 2 digit
date
5

• SQL Commands Classification :


o Data Definition Language – CREATE, ALTER, DROP command
o Data Manipulation Language – INSERT, UPDATE, DELETE, SELECT
command
o Transaction Control Language – COMMIT, ROLLBACK, SAVEPOINT
command

• SQL queries:
DDL Commands
1. CREATE Syntax : Example :
DATABASE CREATE DATABASE CREATE DATABASE
<DBNAME>; EMP_DATA;
2. For using Syntax : Example :
/opening USE <DBNAME>; USE EMP_DATA;
Database
3. To show all Syntax : Example :
available SHOW DATABASES; SHOW DATABASES;
databases
4. To create table Syntax : Example :
CREATE TABLE CREATE TABLE EMP
<table_name> (EMPNO INT ,
(<col_name> ENAME VARCHAR(20),
<datatype> <size> SALARY INT);
constraint,
<col_name> CREATE TABLE EMP
<datatype> <size> (EMPNO INT PRIMARY KEY,
constraint,---------- ENAME VARCHAR(20),
); SALARY INT);

5. Describe table Syntax : Example :


DESCRIBE
– can view the <TABLE_NAME>;
structure of
the table
6

6. Alter table – to Syntax : Example :


change the ALTER TABLE (a) Add an attribute to an
structure of <TABLE_NAME> existing table
the table like ADD/MODIFY/DROP
Adding new <COLUMN_NAME>…; ALTER TABLE STUDENT
column, ADD MARKS INT;
deleting a
column etc. (b) Modify datatype of an
attribute

ALTER TABLE STUDENT


MODIFY MARKS FLOAT;

(c) Remove an attribute

ALTER TABLE STUDENT


DROP MARKS;
7. Drop table - Syntax : Example :
DROP DROP TABLE Command to delete a
statement to <table_name>; database EMP_DATA.
remove a DROP DATABASE EMP_DATA;
database or a Syntax to drop a
table database: DROP Command to delete a table
permanently DATABASE db_name; STUDENT.
from the DROP TABLE STUDENT;
system.
DML Commands
8. Insertion of Syntax : Example :
Record INSERT INTO INSERT INTO STUDENT
<TABLE_NAME> VALUES (11, ‘MEENU’, ‘2005-
(<col_name>,<col_na 10-25’ , ‘ABC’);
me>,…)
VALUES OR
(<val1>,<val2>,…);
INSERT INTO STUDENT
(ROLLNO,SNAME,SDOB,GUID)
VALUES (11, ‘MEENU’, ‘2005-
10-25’ , ‘ABC’);

OR

INSERT INTO STUDENT


(ROLLNO,SNAME,SDOB)
VALUES (20, ‘SHEENA’, ‘2009-
10-13’);

9. Select 1) To display all record To display all details of


statement students.
7

Syntax:
SELECT * FROM Example :
tablename; SELECT * FROM STUDENT;

2) To display selected To display only ROLLNO and


columns and all rows SNAME from STUDENT table.
Syntax:
SELECT SELECT ROLLNO, SNAME
<colname>,<colname FROM STUDENT;
>.. FROM
<tablename>;
To display all details whose
3) To display selected rollno is less than 15.
rows and all columns
Syntax : SELECT * FROM STUDENT
SELECT * FROM WHERE ROLLNO<15;
<tablename>
WHERE <condition>;
To display name of student
4) To display selected whose roll no is 20.
rows and selected
columns SELECT SNAME FROM
Syntax : STUDENT WHERE
SELECT ROLLNO=20;
<colname>,<colname
>
FROM <tablename>
WHERE <condition>;
10. Column Aliases Syntax: Example: Display names of
– renaming a SELECT <COLNAME> all employees along with their
column AS “<new name> annual salary (Salary*12).
FROM <tablename>; While displaying query result,
rename EName as Name.

mysql> SELECT EName AS


Name, Salary*12 FROM
EMPLOYEE;

Output:-
8

11. DISTINCT Syntax : To display unique


clause - The SELECT DISTINCT department number for all
SELECT <COLNAME> FROM the employees.
statement <tablename>;
when mysql> SELECT DISTINCT
combined with DeptId FROM EMPLOYEE;
DISTINCT
clause, returns Output:-
records
without
repetition
(distinct
records)

12. WHERE clause Syntax : To display distinct salaries


- The WHERE of the employees working
clause is used SELECT * FROM in the department number
to retrieve <tablename> D01.
data that meet WHERE <condition>;
some specified mysql> SELECT DISTINCT
conditions Salary FROM EMPLOYEE
WHERE Deptid='D01';

Output:-
9

13. Membership Syntax:


Operator – SELECT * FROM
IN <tablename>
WHERE <colname>
The IN IN
operator (<val1>,<val2>…);
compares a
value with a
set of values
and returns
true if the
value belongs
to that set.
14. ORDER BY Syntax : Example :
clause –
used to display SELECT <colname>… SELECT * FROM EMP
data in an FROM <tablename> ORDER BY SALARY;
ordered ORDER BY <colname>;
(arranged) Output:-
form with
respect to a
specified
column.

By default
displays
records in
ascending
order

To display the
The following query displays
records in
details of all the employees in
descending
descending order of their
order, the
salaries.
DESC keyword
written
mysql> SELECT * FROM
EMPLOYEE ORDER BY Salary
DESC;

Output:-
10

15. Handling NULL Syntax : ➢ Displays details of all


Values those employees who have not
SELECT * FROM been given a bonus. This
<tablename> implies that the bonus column
WHERE <colname> IS will be blank.
NULL/ IS NOT NULL;

mysql> SELECT * FROM


EMPLOYEE WHERE Bonus IS
NULL;

Output:-

➢ Displays names of all the


employees who have been
given a bonus. This implies that
the bonus column will not be
blank.

mysql> SELECT EName FROM


EMPLOYEE WHERE Bonus IS
NOT NULL;

Output:-

16. Substring • % (percent)— ➢ Displays details of all


pattern used to those employees whose name
matching represent zero, starts with 'K'.
one, or multiple
characters mysql> SELECT * FROM
• _ (underscore)— EMPLOYEE WHERE Ename
used to LIKE 'K%';
represent a
11

single char
➢ Displays details of all
those employees whose name
ends with 'a'.

mysql> SELECT * -> FROM


EMPLOYEE -> WHERE Ename
LIKE '%a';

➢ Displays details of all


those employees whose name
consists of exactly 5 letters and
starts with any letter but has
‘ANYA’ after that.

mysql> SELECT * FROM


EMPLOYEE WHERE Ename
LIKE '_ANYA';

➢ Displays names of all the


employees containing 'se' as a
substring in name.

mysql> SELECT Ename FROM


EMPLOYEE WHERE Ename
LIKE '%se%';

➢ Displays names of all


employees containing 'a' as the
second character.

mysql> SELECT EName FROM


EMPLOYEE WHERE Ename
LIKE '_a%';
17. Data Syntax: ➢ To update the name of
Updation – UPDATE table_name student to ‘SANJAY’ whose Roll
to make SET no is 3 in table STUDENT.
changes in the attribute1 = value1,
value(s) of one attribute2 = value2, mysql> UPDATE STUDENT
or more .. SET SNAME = ‘SANJAY’
columns of WHERE condition; WHERE RollNumber = 3;
existing
records in a
table.
12

18. Data Deletion - Syntax: ➢ To delete the details of


The DELETE DELETE FROM student whose Roll number is 2.
statement is table_name WHERE
used to delete condition; mysql> DELETE FROM
one or more STUDENT WHERE RollNumber
record(s) from = 2;
a table

SQL OPERATORS

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Special Operators

Arithmetic Operators:
Ex:
mysql>SELECT 5+10;
or
mysql>SELECT 5+10 FROM DUAL;

Relational Operators:
mysql>Select * from Student Where Marks>=90

Logical Operators:
1. And
2. Or
3. Not
Ex:And
mysql>Select * from Student where Marks>80 and Gender=’M’;
Ex:Or
mysql>Select Rollno,Name,Stream from student where Stream=’Science’ Or
Stream=’Commerce’;
Ex:Not
mysql>Select Name,Marks from Student where not(Stream=’Vocational’);
13

Special Operators:

1. Between…..And
2. Not Between
3. IN
Syntax:
mysql>Select<column_name> From<table_name> Where<column_name> Between
<value1>And<value2>;

Ex:
Mysql> Select Rollno,Name,Marks from student where Marks Between 80 and 100;

Not Between
Ex: Select Rollno,Name,Marks from student Where Marks Not Between 80 And 100;

In:
Syntax: SELECT<column_name> FROM<tablename> WHERE<column_name> IN
(value1,value2);
Ex: Select * from student where stream In(‘Science’,’Commerce’,’Humanities’);

Not In:ex
SELECT * FROM Student WHERE Stream NOT in(‘Science’,’Commerce’,’Humanities’);
14

MYSQL – QUESTION BANK

Write SQL queries to perform the following task:

1. To create database with name BOOK. CREATE DATABASE BOOK;


2. To Open above created database BOOK. USE BOOK;
3. To display list of all available databases. SHOW DATABASES;
4. To create following table: CREATE TABLE EMP
Table Name: EMP (EMPNO INT (10) PRIMARY
Column Datatype Size Constraint KEY, ENAME VARCHAR (25)
name NOT NULL, JOB VARCHAR
EMPNO INT 10 PRIMARY (25), SALARY INT (10), DOJ
KEY DATE, DEPTNO INT (5));
ENAME VARCHAR 25 NOT NULL
JOB VARCHAR 25 -
SALARY INT 10 -
DOJ DATE -
DEPTNO INT 5 -

5. Insert the rows in above table GYM. INSERT INTO GYM VALUES
(‘G101’, ‘Power fit exerciser’ ,
20000 , ‘ABC’);
Write SQL query for the following on the basis of Table EMP given below:
15

6. Write a command to display all details of SELECT * FROM EMP;


table EMP.
7. Write a command to display name of SELECT ENAME, JOB FROM
employee with their job type. EMP;
8. Write a command to display all details of SELECT * FROM EMP
table EMP whose JOB type is CLERK. WHERE JOB=’CLERK’;
9. Write a command to display name of SELECT ENAME FROM EMP
employees whose loc is CHICAGO. WHERE LOC=’CHICAGO’;
10. Write a command to display details of SELECT * FROM EMP
employee whose job type is either CLERK WHERE JOB IN (‘CLERK’,
or SALESMAN. ‘SALESMAN’);
11. Write a command to display distinct job SELECT DISTINCT JOB FROM
types from table emp. EMP;
12. Write a command to display details of SELECT * FROM EMP
Employee in ascending order of ORDER BY HIREDATE;
HIREDATE.
13. Write a command to display name of SELECT ENAME FROM EMP
employees whose Department name is WHERE DNAME IS NULL;
not given.
14. Write a command to display name of SELECT ENAME FROM EMP
employees whose name starts with ‘s’. WHERE ENAME LIKE ‘S%’;
15. Write a command to display name of SELECT ENAME FROM EMP
employees whose name ends with ‘s’. WHERE ENAME LIKE ‘%s’;
16. Write a command to display name of SELECT ENAME FROM EMP
employees whose name contains WHERE ENAME LIKE ‘%S%’;
alphabet ‘s’.
17. Write a command to display name of SELECT ENAME FROM EMP
employees whose name contains ‘s’ as WHERE ENAME LIKE ‘%s_’;
second last alphabet.
18. Write a command to display name of SELECT ENAME FROM EMP
employees whose name length is 4 WHERE ENAME LIKE ‘ ______ ’;
letters.
19. Display details of emp in descending SELECT * FROM EMP
order of Location. ORDER BY LOC DESC;
20. Write a command to change the job type UPDATE EMP
to MANAGER whose empno is 7876. SET JOB=’MANAGER’
WHERE EMPNO = 7876;
21. Write a command to add a new column ALTER TABLE EMP
SALARY in above table emp. ADD SALARY INT;
22. Write a command to modify the datatype ALTER TABLE EMP
of SALARY to float. MODIFY SALARY FLOAT;
23. Write a command to delete a column ALTER TABLE EMP
salary from table emp. DROP SALARY;
24. Write a command to delete a rows from DELETE FROM EMP
table emp whose empno is either 7876 WHERE EMPNO IN (7876,
or 7902. 7902);
25. Write a command to delete all the rows DELETE FROM EMP;
from table emp.
26. Write a command to delete table emp. DROP TABLE EMP;
16

27. Write a command to delete database DROP DATABASE SCHOOL;


SCHOOL.
28. Write the degree and cardinality of the Degree = no. of columns = 6
above table emp. Cardinality = no of rows = 14
17
18
19
20
21
22
23
24
25
26

EMERGING TRENDS

ARTIFICIAL INTELLIGENCE
Artificial Intelligence endeavours to simulate the natural
intelligence of human beings into machines, thus making them
behave intelligently. An intelligent machine is supposed to imitate
some of the cognitive functions of humans like learning, decision-
making and problem solving. AI system can also learn from past
experiences or outcomes to make new decisions.

MACHINE LEARNING
Machine Learning is a subsystem of Artificial Intelligence,
wherein computers have the ability to learn from data using
statistical techniques, without being explicitly programmed by a
human being. It comprises algorithms that use data to learn on
their own and make predictions. These algorithms, called models,
are first trained and tested using a training data and testing data,
respectively.

DEFINE AUGMENTED REALITY

The superimposition of computer-generated perceptual


information over the existing physical surroundings is called as
Augmented Reality (AR). It adds components of the digital world
to the physical world.
27

BIGDATA
Big data is data that contains greater variety, arriving in increasing
volumes and with more velocity. Our posts, instant messages and
chats, photographs that we share through various sites, our
tweets, blog articles, news items, opinion polls and their
comments, audio/video chats etc. Big data not only represents
voluminous data, it also involves various challenges like
integration, storage, analysis, searching, processing, transfer,
querying and visualisation of such data.

IOT THINGS
Internet of things (IoT), is an entity or physical object that has a
unique identifier, an embedded system and the ability to transfer data over
a network.
The Internet of Things refers to the rapidly growing network of connected
objects that are able to collect and exchange data in real time using
embedded sensors. Thermostats, cars, lights, refrigerators, and more
appliances can all be connected to the IoT.
CLOUD COMPUTING
Cloud computing is an emerging trend in the field of
information technology, where computer-based services are
delivered over the Internet or the cloud. The services comprise
software, hardware (servers), databases, storage, etc. These
resources are provided by companies called cloud service providers.
Cloud computing offers cost-effective, on-demand resources. A user
can avail need-based resources from the cloud at a very reasonable
cost. We already use cloud services while storing our pictures and
files as backup on Internet, or host a website on the Internet.

CLOUD SERVICES AVAILABLE OVER NETWORK


There are three standard models to categorise different
computing services delivered through cloud
• Infrastructure as a Service (IaaS),
• Platform as a Service (PaaS), and
• Software as a Service (SaaS).
28

INFRASTRUCTURE AS A SERVICE (IAAS)


The IaaS providers can offer different kinds of computing
infrastructure, such as servers, virtual machines (VM), storage and
backup facility, network components, operating systems or any other
hardware or software Using IaaS from the cloud, a user can use the
hardware infrastructure located at a remote location to configure,
deploy and execute any software application on that cloud
infrastructure

PLATFORM AS A SERVICE (PAAS)


Through this service, a user ca n i n s t a l l a n d ex ec u t e an
application without worrying about the underlying infrastructure and
their setup Suppose we have developed a web application using
MySQL and Python. To run this application online, we can avail a
pre-configured Apache server from cloud having MySQL and Python
pre- installed. Thus, we are not required to install MySQL and Python
on the cloud, nor do we need to configure the web server.

SOFTWARE AS A SERVICE (SAAS)


SaaS provides on-demand access to application software,
usually requiring a licensing or subscription by the user. While
using Google doc, Microsoft Office 365, Drop Box, etc., to edit a
document online, we use SaaS from cloud. A user is not concerned
about installation or configuration of the software application as
long as the required software is accessible.

BLOCKCHAINS

We can define blockchain as a system that allows a group of


connected computers to maintain a single updated and secure
ledger. Each computer or node that participates in the blockchain
receives a full copy of the database. It maintains an ‘append only’
open ledger which is updated only after all the nodes within the
network authenticate the transaction.

You might also like