Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
37 views

SQL Full Course in 10 Hours - SQL Tutorial - Complete SQL Course For Beginners - Edureka - YouTube - English

Uploaded by

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

SQL Full Course in 10 Hours - SQL Tutorial - Complete SQL Course For Beginners - Edureka - YouTube - English

Uploaded by

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

[Music]

did you know SQL is a high demand

technical skill due to its data analysis

capabilities for businesses in a wide

range of areas just robust and easy to

learn

SQL is requested by many job profiles

since it goes hand in hand with

Technologies indeed.com one of the

largest employment portals examined over

32 000 Plus data job listings and

discovered that SQL is listed in 42.7

percent of them making it current most

in demand technical talents for

potential employees

hello everyone and welcome to this

session we are currently watching an

edureka SQL full course video by the end

of this video you will have a thorough

understanding of SQL all the way from

Theory to practical application that

will help you master it if you love

watching videos like these then

subscribe to edureka's YouTube channel

and click the Bell button to never miss

out any updates from us also if you want

to learn more about SQL after watching

the session and wish to obtain edureka's

SQL training and certification course

please see the link in the description


below now let's begin with our agenda

where we'll have a brief overview of

what we'll cover in this SQL full course

video we'll start by seeing what is SQL

next we have SQL Basics followed by SQL

operators

now is the time to study deeply into

sql's technical components we'll start

with understanding what is normalization

and triggers in SQL now once this is

done we'll understand what our joints

and functions in SQL we will then

compare SQL to mySQL and subsequently

SQL to nosql we hope that the session

assists you in getting jobs in the

industry in order to accomplish this we

will look at how a career in SQL Works

followed by some essential SQL interview

questions now after all this we'll head

over to how SQL is required in data

science

followed by postgresql and SQL server at

last we'll look at some SQL server

interview questions with answers

please take till the end now let's start

with our first topic that is what is SQL

[Music]

the first topic is traditional file

system in today's Computing World


managing data is a huge task for our

convenience we store the data and

documents in different location and this

is called file system

without a file system information placed

in the storage medium would be one large

body of data we won't be able to tell

where information stops and where it

begins let's look at the formal

definition file system is one which

controls how the data is stored and

retrieved it is nothing but information

stored in different computer files

usually while storing a small amount of

data the file system is effective but

when it comes to storing the enormous

amount of data the file system fails

let's look at some of the problems of

file system the first problem is data

redundancy when we store similar data in

different location of a computer data

gets duplicated and this will lead to

data redundancy this will increase the

storage size and also leads to failure

of security features because of this the

file system is highly vulnerable in

nature data redundancy will cost a user

not only in terms of security but also

economically

the second problem is limited data


sharing and lack of security data

sharing and security are closely related

sharing data among multiple users

introduces a lot of security risk in

terms of spreadsheet data and other

documents the inbuilt file system

programs provides only the basic

security option but they are not used

most of the time because of this

negligence we might face some bigger

problems in the near future the third

problem is the difficulty of getting

quick answers this is one of the major

problems in file system because file

system doesn't allow multiple users to

access the same data at a given point of

time this means that multiple uses a

different work location cannot access

the same data simultaneously this will

limit the access to important data if

multiple users search for the same data

at a given point of time

the next problem is data dependence in

the file system files and records are

described by a specific physical format

that is coded into the application by

the programmers if the format of any one

record was changed then we need to make

sure that all the remaining records


format is updated this information has

to be updated in the system also any

changes in storage structure or access

methods could greatly affect the process

this might result in failure of that

particular application so these were few

problems that were faced using the file

system and the solution for this is SQL

and database let's now look at the

evolution of SQL SQL was developed at

IBM by Donald D Chamberlain and Raymond

F boys in the early 1970s

it was initially called as SQL that is

Structured English query language but

later it was chained to SQL because SQL

was a trademark of UK based engineering

company in the year 1986 American

National Standard Institute that is ANSI

and the international standards

organization that is ISO have deemed the

SQL language as a standard language in

relational database communication this

is how SQL evolved since we have

understood the evolution of SQL let's

head to the next topic that is what is

SQL people from technical background may

find this silly but for a beginner it is

really important to understand each and

every aspect of this topic the main

focus of this entire session will be on


this part so now let's understand what

is SQL SQL is an abbreviation for

structured query language which also

goes by the name SQL even today it's a

language used by the database domain SQL

can be used only for relational type

database and not for the others

relational database is a database which

has the tabular method of storing data

usually it consists of rows and columns

let's now see what SQL can do SQL is a

core of relational database which is

used for accessing and managing the

database with the help of SQL statements

you can add columns update or delete

rows of data we can also retrieve

information modify database and perform

many more actions the different subsets

of SQL commands are as follows ddl that

is data definition language it simply

deals with the description of the

database schema and used to create and

modify the structure of database objects

in the database it allows you to perform

various operation on the database such

as create alter and delete objects ddl

is very popular and extensively used

when compared to other commands moving

on to the next command DCL that is data


control language it allows you to

control access to the database Grant or

revoke are the DCL commands Grant gives

user access privileges to the database

while revoke withdraws user access

privileges given to the user with the

help of Grant command so the next

command is tml that is data manipulation

language it allows you to access and

manipulate data

you to insert update delete and retrieve

data from the database so what does each

of this command do so the insert command

is used to insert data into the table

while update is used to update existing

data within the table and at last delete

is used to delete records from the

database

final command is TCL that is transaction

control language it allows you to deal

with the transaction of the database few

of the TCL commands are commit rollback

save point and set transaction so these

were the SQL commands to understand SQL

in a better way let's use an analogy if

two people won't communicate with each

other then they have to use a language

that is understood by both of them here

John wants to start a conversation with

Dave and he uses English language to


start his conversation this language is

known to Dave as well so they will

continue their conversation but what if

one of them didn't understand what the

other person spoke there won't be any

conversation at all relating this

analogy if we consider these two people

one as user and the other as database

then that language which is used to

communicate between these two is called

SQL similarly how a language has a

grammar and various rule on how it

should be used even the SQL has its own

directives I hope you have clearly

understood what exactly SQL is let's now

head to the next topic that is

advantages of SQL so the first feature

is SQL has well-defined standards as it

says developers of SQL has clearly

mentioned how exactly each and every

query has to be written there is no room

for ambiguity when it comes to writing a

query the standards have to be followed

the second Advantage is SQL is easy to

learn yes SQL is a language that is used

to work with a database since SQL has a

large user base as well as well-defined

standard for a beginner it is really

easy to learn the next one is in SQL we


can create multiple views this is one of

the unique and early feature that SQL

came up with view is nothing but

creating a virtual table a virtual table

is a temporary table for certain use by

doing this we can protect the Integrity

of the data SQL has the ability to not

only create a single view but can create

multiple views fourth one is SQL queries

are portable in nature it means we can

execute the SQL query in one system and

execute the same query in an another

system without changing the format but

the condition is that the environment

setup of these two system has to be same

else the query won't be executed the

next Advantage is interactive the main

purpose of SQL is to communicate with a

database we can write complex queries to

fetch the results from the database and

these queries can be easily understood

by anyone so these were some of the

advantages of SQL let's head to the next

topic that is SQL in real time since SQL

is a language that is used to operate on

the database we need to look at the

bigger picture of the data management

industry here if I say database it

includes SQL language as well the

database is used in different verticals


like online stores Healthcare Providers

libraries financial industry retail

industry government agencies and many

more now let's consider some real-time

examples of the use of SQL and database

the first one is education sector

database systems are frequently used in

schools colleges and universities to

store and retrieve the data this data

may be regarding student staff details

course detail exam details attendance

details and fees details there's a lot

of interrelated data that needs to be

stored and retrieved efficiently to

understand the magnitude of impact that

the database has made in this field try

to imagine the days when the results

were only declared on the school notice

board isn't it easier now to access your

exam results with just one click who

wouldn't say no to such a drastic change

also nowadays the online exams have

increased significantly this has

increased the speed of assessment when

compared to the olden days all these are

possible because of SQL and database

technology the next sector is Healthcare

sector there were days when people used

to stand in front of the clinics and


hospitals to get an appointment with a

doctor but now the time has changed in

hospitals and medical institutions

maintaining data related to doctors

patients and staff is a huge task

effectively coordinating among these

three has to be handled seamlessly with

the help of SQL and database this

industry has gained a lot with the

introduction of SQL and database

inventory management has been effective

the next one is retail industry every

year leading e-commerce Trends come up

with great offers discounts based on

your personalized shopping to come up

with all this they use database and

other technology the industry utilizes

the database and SQL technology

extensively and retail industry

customers data has to be managed

effectively there's no scope of error

when it comes to handling the data with

the instigation of SQL and database

system the retail industry can not only

secure the data but also can get the

real-time analysis which in turn helps

him to make a lot of profit and the

final one is financial sector when we

speak about this sector it's really hard

to even imagine what goes behind the


scene only the experts know how much

data will be processed every second

managing money assets shares Etc in a

real time is a tedious task SQL and

database technology is helping the

financial sector to achieve its primary

task SQL queries can be also used to

check the fraudulent activities looking

at the issues of fraudulent activity

effective fraud detection requires a

financial organization to process a huge

amount of customer purchasing data so

these organizations have to store and

retrieve data effectively without

causing any burden on another branch of

the same organization these were the few

sectors and industries where the SQL is

used in day-to-day transaction this

brings us to the end of this session I

hope you have clearly understood what is

SQL its Evolution and its application

[Music]

foreign do you know when SQL was born

well let me answer that question for you

SQL was developed at IBM by Donald Lee

Chamberlain and Raymond F boys in the

early 1970s it was initially called as

sequel that is Structured English query

language but later it was trained to SQL


because SQL was a trademark of UK based

engineering company SQL is said to be a

powerful language reason for that is it

uses very simple English sentences and

also uses very few lines it uses common

words such as select insert update and

many more to perform its core

functionalities

SQL is known to be a declarative

language when you write a query you have

to describe what needs to be done and

you don't have to worry regarding the

flow of the query it will be handled

internally by the dbms that you are

using

now let's look at some of the features

of SQL so the first feature is SQL has

well-defined standards as it says

developers of SQL has clearly mentioned

how exactly each and every query has to

be written there is no room for

ambiguity when it comes to writing a

query the standards has to be followed

SQL is easy to learn yes SQL is a

language that is used to work with the

database since SQL has a large user base

as well as well-defined standards for a

beginner it is really easy to learn next

one is in SQL we can create multiple

views this is one of the unique and


early feature that SQL came up with view

is nothing but creating a virtual table

a virtual table is a temporary table for

certain use by doing this we can product

the Integrity of the data SQL has the

ability to not only create a single view

but can create multiple views finally

SQL queries are portable in nature it

means we can execute the SQL query in

one system and execute the same query in

an another system without changing the

format but the condition is the

environment setup of these two system

has to be same as the SQL query won't be

executed

so these were some of the features of

SQL now let's look at the next topic

that is data and database

firstly let's look at what is data so

the standard definition for a data is

values from differences which has been

translated for some purpose and this

purpose can be anything source for the

data can be like temperature reading

financial data videos blogs text Etc it

goes on in the end it should make a

meaningful sense only then we can

consider it as a data

this image clearly depicts the different


source of data so we can clearly

understand that the data source can be

anything since we are clear about what

data is all about let's head to the next

topic that is what is database

firstly let's look at the formal

definition for a database

a database is an organized collection of

data where the data is stored and

accessed electronically from a computer

system to make you understand what it

means let me use an analogy to explain

the concept of database consider a

library usually the library contains a

huge collection of books of different

genre here library is a database and

these books are the data in the image we

can see a person performing an action on

the data and those action can be like

create store update Etc when the user

sends the instruction as well as the

data it will be stored inside the

database after certain process and this

entire process is bi-directional that is

control flows on both the sides next I'm

gonna talk about different types of

databases there are different kinds of

databases that are in use today and

these databases are classified based on

capabilities features functionality size


and performance so few of them are

distributed database object oriented

database centralized database

operational database graph database

Cloud database nosql database and

finally relational database among these

databases the two popular types that are

widely used are first one relational

database and second one nosql database

relational databases generally uses SQL

language and we are going to learn more

about it in the coming modules moving on

let's look at some of the popular

databases that are widely used today so

they are mongodb postgres Microsoft

Access Microsoft SQL Server MySQL and

Oracle DB these are the few popular

databases that are used today each one

of them has its own pros and cons since

we have already started the topic of

database it wouldn't be fair to drop

this topic abruptly so I shall discuss a

few basic database related queries the

first query is how to create a database

to explain this let me jump into my SQL

workbench this is the interface of MySQL

workbench on the left side of the screen

we can see the database in the center

area we are gonna write our queries at


the bottom part we are going to get the

status of the query that has been

executed so you might wonder why I'm

using MySQL workbench for executing SQL

queries well SQL is a language that is

used to communicate with the database

whereas MySQL workbench is a database

management system so MySQL workbench

allows us to use SQL queries to

communicate with the database can't we

use other dbms yes we can but the syntax

of the queries May slightly vary

so let me explain you the first topic

that is how to create a database and the

Syntax for this is

create database are the keywords used to

create a database followed by that we

have to specify the name of the database

here I'm using edureka as a name for my

dbms so let me select this entire

statement and click on the lightning

icon so I can see at the bottom that the

database with the name edureka has been

created so let me refresh it so we can

see that the database with the name area

has been created so the next topic I'll

be discussing is how to delete a

database and the syntax for this is

drop database are the keyword used to

delete a database and followed by that


will be the database name so let me

select this entire query and click on

the lightning icon so we can see that

the database with the name edureka has

been deleted

so these were the few queries related to

database the next topic that we are

going to learn is table so what is a

table a table in a database is nothing

but a collection of data in a tabular

way it consists of rows and columns the

table contains data elements also known

as values using a model of vertical

columns and horizontal rows the point of

intersection of a row and a column is

called a cell a table can have any

number of rows but should have a

specified number of columns to

understand the concept of a table in a

better way let's look at the image so

the name of the table here is person

when we create a table it has to have a

name a table without a name doesn't

exist so what is tuples a single row of

a table which contains a single record

for that relation here there are six

tuples next is attributes features of an

entity is called attribute an attribute

has a name and a data type here there


are four attributes those are ID first

name last last name and date of birth so

I hope you have understood the concept

of table let's Now understand the table

constraints so what are table

constraints in simple words it is a

restriction that are specified by the

user while creating a table so you may

wonder why these kinds of constraints

are required

the answer for that is even though a

table stores the data that data has to

be of certain format to ensure the data

Integrity we use constraints these

constraints have to be decided during

the creation of a table if we want to

change the constraint then we have to

delete the table and then we have to

create a new table using the new

constraints

few of the constraints that are used

most of the times while creating a table

are check default primary key foreign

key not null index and unique since we

have understood what table is let's look

at some of SQL queries related to the

table the first one is how to create a

table to understand this let's head to

the MySQL workbench

to create a table we need an active


database since we had deleted the

previously create database let me create

the database once again

so we can see that we have a database

with the name edureka so now let me

create the table and the Syntax for

creating a table is

create table is a keyword used to create

a table followed by that we have

mentioned the table name we need to make

sure that the table name is unique keep

in mind that in a database there cannot

be two tables with the same name inside

the table we have declared the columns

along with the data type and we have to

end the query with a semicolon so let me

execute this query

so we can see that the table EMP has

been created

so the next query I'm going to discuss

is how to delete a table and the Syntax

for this is

we shall use drop table keywords to

delete a table and followed by that we

have to specify the table name so let me

select this entire query

and we can see that the table with the

name EMP has been deleted

with all the basic introduction


understood so far let's Now understand

some SQL basic queries let me begin this

by introducing the most basic and widely

used query that is Select statement and

the syntax is Select column name from

the table name we can specify the name

of the columns that are present in the

table also note that if you want to

display all The Columns of a table then

use star operator

now let's jump into execution part to

explain the entire SQL queries I'm using

student table and the student table has

student ID first name last name address

City and marks as its columns so the

Syntax for select statement is

select star from student since we have

to display all the columns I'm using

star operator so let me select this

entire query

so we can see that the entire table has

been displayed so this is one of the way

in which we can use select statement the

another method is if we want to select a

particular column then we have to

specify that column name and the Syntax

for that is

so we can see that from the table we

have selected only first name and last

name
usually select statement is used to

select the data from the database

so the next SQL query that I'm going to

discuss is where Clause where Clause is

used to filter records where Clause is

used to extract only those records that

fulfill the specified condition to

demonstrate where Clause let me assume

the scenario if I want the name of the

students who are from the city Goa then

my where Clause query will be something

like this

select first name from student where

city is equal to Goa so let me select

this query and execute it so this is the

output

now let's look into and or not

statements

if we need to add two or more conditions

in the where Clause then we can use the

above mentioned operators these keywords

will add more complexity to the query so

the first operator is and operator this

operator display a record if all the

conditions separated by the and operator

are true let's look at the syntax select

columns from table where condition 1 and

condition 2 has to be true to understand

the example let's dive into the demo


part

I want to display the details of the

student who has the first name as Bharat

and last name asking to achieve this I

am using and operator so let me execute

this query

yes I got the output for the student

name Bharat Singh the next operator I'm

gonna discuss is or operator

or operator usually displays a record if

any of the conditions separated by or is

true I the Syntax for this is Select

columns from table where condition 1 or

condition 2 is true to understand the

example let's dive into the demo I want

to display the details of a student who

has the first name as boovi or the last

name as Kumar to achieve this I am using

or operator here any one of the

condition has to be true so this is the

query to execute a scenario

so we have got the output for the

student with the name bhuvi Kumar so

let's head to the next operator that is

not operator so this operator display a

record if the condition or conditions

are not true so the syntax is Select

columns from table where the condition

is not true let's see how this example

works here I want to display the details


of the student who does not have the

first name as Ashok to achieve this I'm

using not operator

in this we can see the details of all

the students except Ashok so the next

query I'm going to discuss is insert

into if we want to insert any record or

data into a table then we can use insert

query and the Syntax for this is insert

into is a keyword that is used in insert

query followed by that we have to

specify the table name and columns after

that we have to specify the values let's

look at the example to clearly

understand how exactly this query works

so this is the example for insert query

so we're gonna insert first name as

Manoj last name as Sharma address as 0 7

mg Road and city as Jaipur also the

marks is 438 so let me execute this

query

so we can see that the data has been

inserted to check whether the data has

been inserted or not let me use select

query

so we can clearly see that Manu Sharma

details has been added to the table

next I'll be discussing few aggregate

functions
an aggregate function is a function

where the values of multiple rows are

grouped together as input on certain

criteria and a single value is written

we often use aggregate functions with

the group by and having Clauses of the

select statement so we will be

discussing Group by having in the later

part of the session

some of the aggregate functions are

count sum average minimum and maximum so

let's discuss each one by one so the

first one is Count this function Returns

the number of rows that math specified

criteria so the syntax is count of

column name from table where the

condition so now let's try this example

in MySQL workbench using this query I

will calculate the number of student ID

that is present in the table so let me

select this query

in the output we can see that the count

of the student ID is 6.

the next aggregate function is average

an average function Returns the average

value of a numeric column so the Syntax

for this is Select average of column

from table where condition

let's execute this example here I am

trying to find the average marks code by


all the students so let me select this

query

so the average Mark scored by all the

students is 480.3333

the next aggregate function is sum

usually some function Returns the total

sum of that particular column the syntax

is Select sum of column from table where

condition so let me execute this example

in this example I am trying to find the

total marks scored by all the students

so let me select this query

the total marks scored by all the

students is 2882.

moving on to the next aggregate function

that is minimum

minimum function will return the

smallest value of the selected column

and the syntax is Select Min of column

from table where condition so let me

execute this example if I want to know

the student name who has scored minimum

marks I'll use this query so let me

select this query

Ashok Sinha has scored 385 marks and

this is the minimum marks in this entire

table

and the last aggregate function that we

are going to discuss is Max


Max function Returns the largest value

from the selected column and the syntax

is Select Max of column from table where

condition let's execute this example

so this is the example for maximum

function so let me execute this query

so we get the output that is Bharat

Singh has scored 580 marks so 580 marks

is a maximum marks in the entire table

next SQL query is Group by Group by is a

functionality used to arrange a similar

type of data into a group for instance

if the column in a table consists of

similar data or values in different rows

then we can use Group by function to

group the data the syntax is Select

column from table where condition Group

by the same column let me execute this

example

I want to count the number of students

who are from different cities if there

is any student from same city then the

account will be incremented at the end

the output will have all the city name

with the count of the students from that

particular City so let me execute this

query

we got the count of student from

different cities since all the students

are from different city we can see that


the count is 1 in all the cases if the

data is large we can clearly get to know

how effective this query is

next question is having

this class is used to place condition

where we need to decide which group will

be part of the final result set the

having Clause was added to SQL because

the where keyword could not be used with

aggregate function such as sum count min

max Etc so the syntax is Select column

from table where condition Group by the

column and having condition so let me

execute this example in MySQL workbench

so that you'll get an idea about having

clause

from the table if I want to display the

students who have scored more than 500

then I'll specify that condition after

having keyword so let me execute this

query

so we can see that there are two

students Ashok and bhuvi who have scored

more than 500 marks

moving on to the next query that is

order by order by keyword is used to

sort the result set in ascending or

descending order this keyword is used to

sort the result set in ascending or


descending order the order by keyword

shall sort the record in ascending order

by default if we want to sort the record

in descending order then we need to use

the descending keyword so let me explain

the syntax select columns from table

order by columns either by ascending or

descending let me execute this example

in this example we will get the count of

students from different city and we are

arranging the city in descending order

so let me execute this query

we can see that the cities are arranged

in descending order based on the

starting alphabet

the next SQL query that we're gonna

learn is null values

in SQL we used a null term to represent

a missing value a null value in a table

is a value that appears to be blank a

field with a null value is a field with

no value in SQL keep note that a null

value doesn't mean that the value is

equal to zero to check the null value we

are not supposed to use the operators

such as greater than less than equal to

these operators are not supported in SQL

we have special keywords those are is

null and is not null

first let's look at the is null operator


is null operator is used to test the

empty values and the Syntax for this is

select columns from table where column

is null so let me execute this example I

want to display the student's name whose

marks is null so let me select this

query and let me execute this

since all the students have marks and

none of them has null value in the

output we don't have any student names

the next query is is not null the is not

null operator is used to test for

non-empty values and the syntax is

Select column from table where column is

not null so again let me execute this

example I want to display the student

names whose marks is not null so let me

execute this query

since all the students have marks all

the student names are displayed

let's move to the next query that is

update generally the update command is

used to modify rows in a table the

update command can be used to update a

single field or multiple fields at the

same time let's look at the Syntax for

update statement update table set column

equal to Value where condition let's

execute this example


here I want to change the name of the

student with student id1 previously the

student with student id1 was Ashok

Sinnoh now I want to change his name to

Amar Kumar so let me execute this query

so we can see that the student name has

been updated

to check the student table let me

execute this query

and we can see that the name of student

id1 has been changed from Ashok Sinha to

Amar Kumar in the next query we are

going to discuss is delete the SQL

delete command is used to delete rows

that are no longer required from the

database tables it deletes the whole row

from the table the syntax is delete from

table where condition so let me execute

this example

if we want to delete a record from

student table where the city is Mumbai

let me execute this query

so we can see that the query has been

executed to check the table let me

execute the statement

and student with the id1 has been

deleted

next let's discuss in and between

operators

in operator is used to specify multiple


values inside the where Clause it acts

as multiple or let's look at the syntax

select column from table where column in

value let me execute this example if we

want to display the record of a student

who are from certain city then we can

use in operator in the given example

let's display the name of the students

along with their IDs who are from Delhi

Goa Pune and Bengaluru let me execute

this query

in the output only those students from

the specified city name are displayed

the next operator is between

operator will select a particular value

within the specified range it s

compulsory to add the beginning and the

end value let us look at the syntax

select column from table where column

name between value 1 and value 2. let's

execute this example

if we want to display the record of

students whose marks are in certain

range then we can use between operator

in the given example let's display the

name of the student along with their ID

who has code in the range of 400 and 500

so let me execute this query

in the output only those Student Records


who have scored in the range of 400 and

500 has been displayed

so the next topic we're gonna cover is

aliases and SQL Alias is a process of

giving a table or a column a temporary

name so that it helps when the query is

complex it increases the readability of

the query this renaming is temporary and

the table name does not change in the

original database we can Alias a column

or a table so the first concept is

column aliasing and the syntax is Select

column name as Alias name from table so

let me execute this example

in the student table the column name

student ID is bit long when we write a

nested query we might face some trouble

in order to tackle such situation that

Alias that student ID column as ID so

let me execute this query

and we can see that the column student

ID has been Alias to ID next is table

aliasing now let's look at the Syntax

for table Alias and the syntax is Select

column from table as Alias name so let's

execute this example

we generally use as keyword in aliasing

so let me execute this query

by using the technique of table aliasing

I have displayed the names of the


students from the student table

so that was a basic concept of SQL

[Music]

not in so not keywords is not is

basically logical operators and it is

used along with other operators like in

and other so we've just seen one example

where we want to show the Departments

which are lot in Hyderabad so this is

the repetition of the same example

in the previous example which I shown I

included only one locations but we can

use multiple keywords if you're using

the in keywords we'll see the example

just now n in operator fetches values

from a set of literals

so this conditions is generally used

when we want to fetch values from

multiple values in a single statement so

it's not that I can use only in I can

use or operators so if there are only

one or two conditions I can either use

or operator or in operator but if the

values are more it is not a good idea to

use so many or operators or logical

operators let's assume I want to see the

results intensities

so if I write if like where location is

equals to Mumbai or New Delhi or


Hyderabad or Bangalore or Chennai it is

not readable

it's not good so instead of writing so

many or operators we can use in

operators so the in operator we

basically include all the values out of

which we want to filter our results so

we want to fetch our values

so let's see with an example

so let me open a new query window I'm

going to select

some Department

so if I want to see the results or see

the Departments which are either in

Chennai or Bengaluru so I'll write and

write select star from department

where location in it can be in any one

of these location that's how we are

Bangalore

don't forget to include strings or

characters in single codes in SQL so

this will fetch the desire results so we

can use multiple values in the

parenthesis if we use in comparison

operator

so if I use not in then this will go in

a negation and will show the opposite of

what in operator is doing

so we have discussed not in as well as

in so if there are multiple values so


instead of R we have to use it is good

practice to use in keyword

then basic compression operators we have

greater than equals to less than greater

than equals to so this is pretty much

self-explanatory so if I want to select

the employee whose salary is greater

than 20 000 so let's see how we'll get

the results

so I can use the previous window so

there's celery instead of this I can

write salary is greater than 20 000.

so I'm getting three results

so I have three records or three rows or

three employees whose salary is greater

than twenty thousand so if I include

greater than or equals to then I guess

I'll get four results oh I don't think

so we have a salary of twenty thousand

yeah no we don't have

so let's let's take the example of

thirty thousand here so we'll get the

three results but if I remove the equals

to keywords then of course we'll get

only two rows in the result set

and if I use the equals to then we'll

get the only single row which will

satisfy the desired or required

condition
so this is how we use a various operator

greater than equals to less than greater

than equals to

again this example we can use equal

operator it will satisfy the desired

conditions fetch the results

comparison operator is a like how we use

the like keywords in compression

operator

so generally we use like operators to

perform wildcard searches of valid

search string values as I mentioned

earlier that like keyword is generally

used when we are filtering or fetching

the strings so it used with two wild

cards one is a percentage percentage

denotes zero many characters and

underscore denotes one characters so

that's it so in the first example as you

can see I'm getting the values from the

Department table whose locations

starts with C or the C alphabets

let's see how we can use it

so we'll first see how we use the

percentage wildcard

so if I want to know that what are the

different departments where the

locations start with the alphabet C so

we will write select star from

Department
we have loc I have to use the like

keyboard like parenthesis and then the

keyword C with a percentage sign that is

wild card

will get the results

so if I'll just change the order if I

write the wild card first and then see

it means I have to show the Departments

whose location ends with C so if I'll

write it I here then again I'll get the

desired cell because I am fetching the

rows whose location ends with the I

keyboard or I alphabets

so if I use first wild card and then

alphabet it means it ends with if I'll

first use the alphabet and then World

Cup means it's start with

if I write something like this it's C

then Wildcat and I it means it start

with c and it ends with I so fetch me

the locations Who start with C because

I'm using the C before the wild card and

since I'm using I after the wild card so

it ends with I if I'll execute this

query again it will show me the same

results because but if I change it for

example I'm starting with h and ending

with I so there is no Department with

such a condition so we'll get a empty


result set now if I need to show that

show me the department who starts with h

in that case all I have to do is that we

have to remove the I so we have to use

the keyword before the wild card and it

will show us the result itself

so along with percentage science we use

underscores also as a wild card

so in this example as you can see the

second example select department or

location from department for locations

like so it means the first three words

should be c-h-e-n then we can use

underscore so we have to first satisfy

the first keyword so the first three

should be this so this is how we use the

underscore wildcard

the last topic of this module is the

case expression so case Expressions

helps us to kind of you know simulate

the if then else statement like in most

of the programming language we use if

else so this helps us to write the same

only point with a case statement is that

as you can see in the node we cannot use

null values in the case statement

because it always use the equals to

operator

and we cannot use equals to operator

with the null keyword we have to use is


null that I will show you after this

example so let's assume I'm

fetching values from employee so if I'm

looking for the salary column there are

few rows which are having null values

and there are few rows which having

values in it so if I want to see that

what are the different employees which

have uh null values for the salary

column so if I try to write where salary

equals to null then I won't get any

result here because equals to operators

does not work with null so if I'm

checking now we have to use is null if

I'll execute this query again I'll get

the desired result if I want to check if

I want to fetch the columns which do not

have null values for the salary column

then we have to use is and then we have

to use the not logical operator is not

null

so not logical operators is always used

in combinations with other operators

we get all the employees do not have

null values for the salary column so

that is the reason we are using case

expression so we cannot use the null

values otherwise it will break because

we use the equal operators and equal


operators not used along with null so

this is how the syntax of case

Expressions as you can see we have

declared a variable int input its type

of end and we have set the values is

equals to two it's just an example so we

have hard coded the value here in this

example so we are selecting case I am

just selecting that if the value is 1

then we'll show the output as 1 when it

is 2 then we are showing the output S2

when it is 3 then we are showing output

as a 3 and if it is not out of any these

three values one two and three then

we'll show the messages your message

this is how we are doing this example so

let me give you one example for that let

me do one thing let me find out the

states the cities where my department is

so as we know the Chennai is in Tamil

and Bangalore is in Karnataka so let's

see how we can do that using a case

statement so we have to write select

then case keyword and the case keyword

will Define which columns you want to

fetch so I am fetching the location

and then we'll write the band condition

so I'm writing ban Chennai then show the

result as Tamil Nadu when

Bangalore then let's say Karnataka


and I'm writing an else condition if it

is not part of anything so let's just

write no idea so we have to end the when

condition

then we have to write from which tables

we are basically fetching this

if I'll execute this query I'll get the

field is Chennai I'm getting the results

seminar and if it is Bangalore then I'm

getting as KR and since there's some

departments which do not have any values

like hyderabads we are getting is just

no idea so this is how we can use if

else conditions in SQL statement or

select statement by using case

expression important point is that we

should not deal with we'll be using null

because we use equals to operator

[Music]

what is normalization

database normalization is a technique of

organizing the data in the database it

is a systematic approach of decomposing

tables to eliminate data redundancy it

is a multi-step process that puts data

into Tableau form removing the

duplicated data from its relational

tables on the screen we just saw that

the table is getting decomposed into two


smaller table is it really necessary to

normalize the table that is present on

the database well every table in the

database has to be in the normal form so

normalization is used mainly for two

purpose so the first one is it is used

to eliminate repeated data having

repeated data in the system not only

makes the process slow but will cause

trouble during the later part of

transactions and second one is to ensure

the data dependencies make some logical

sense yes usually the data is stored in

database with certain logic huge data

sets without any purpose are completely

waste it's like having an abundant

resource without any application the

data that we have should make some

logical sense normalization came into

existence because of the problems that

occurred on data now let's look at those

problems and these are known as data

anomalies if a table is not properly

normalized and has data redundancy then

it will not only eat up the extra memory

space but will also make it difficult to

handle and update the database let's

look at the first anomaly that is

insertion anomaly suppose for a new

position in a company Mr rakshit is


selected but the department has not been

allotted for him in that case if we want

to update his information to the

database we need to set the department

information as null similarly if we have

to insert data of thousand employees who

are in similar situation then the

department information will be repeated

for all those thousand employees this

scenario is a classical example of

insertion anomalies the next one is

update anomaly what if Mr rakshit leaves

the company or is in no longer the head

of the marketing department in that case

all the employee records will have to be

updated and if by mistake we miss any

record it will lead to data

inconsistency this is nothing but

updation anomaly and the final one is

deletion anomaly in our employee table

two different pieces of information are

kept together that is employ information

and Department information hence at the

end of financial year if employee

records are deleted we will also lose

the department information this is

nothing but deletion anomaly so these

were some of the problems that occurred

while managing the data to eliminate all


these anomalies normalization came into

existence there are many normal forms

which are still under development but

let's focus on the very basic and the

essential ones only

so we will be talking about first normal

form second normal form third normal

form and finally end this session with

Boy Scout normal form so without wasting

further time let's proceed to First

normal form

in first normal form we tackle the

problem of atomicity here atomicity

means values in the table should not be

further divided in simple terms a single

cell cannot hold multiple values if a

table contains a composite or

multi-valued attributes it violates the

first normal form

so the following functions will be

performed in first normal form the first

one is it removes repeating groups from

the table and next it creates a separate

table for each set of related data and

finally it identifies each set of

related data with the primary key to

understand this in a better way let's

look at the given table

in the employee table we have employee

ID employee name phone number and salary


as columns we can clearly see that the

phone number column has two values thus

it violates the first normal form now if

we apply the first normal form to the

above table we get the following result

in this table each and every row is this

thing that is no cell has multiple

values the table has achieved atomicity

first normal form is simple and can be

easily identified in the table we can

clearly see there is no multiple values

in each and every column thus the first

normal form is achieved

now let's move to Second normal form

second normal form was originally

defined by EF chord in 1971. a table is

said to be in second normal form only

when it fulfills the following condition

the first condition is it has to be in

first normal form

second one is the table also should not

contain partial dependency here partial

dependency means the proper subset of a

candidate key determines a non-prime

attribute so what is a non-prime

attribute let's understand this in a

simple way attributes that form a

candidate key in a table are called

Prime attributes and the rest of the


attributes of the relation are non-prime

for a table Prime attributes can be like

employee ID and Department ID and the

non-prime attributes can be like office

location

to understand second normal form let's

consider this table

this table has a composite primary key

that is employee ID and Department ID

makes the primary key the non-key

attribute is office location in this

case office location only depends on

Department ID which is only the part of

primary key therefore this table does

not satisfy the second normal form

so what to do in such scenario the

answer is simple split the table

accordingly to bring the stable to

Second normal form we need to break the

table into two parts which will give the

following tables the first table has

employee ID and Department ID as columns

the second one has Department ID and

office location as columns as you can

see we have removed the partial

functional dependency that we initially

had now in the table the column office

location is fully dependent on the

primary key of that table which is

nothing but Department ID


I hope you have understood second normal

form now that we have learned first

normal form and second normal form let's

head to the next part of this

normalization

next topic is third normal form

third normal form is a normal form that

is used in normalizing the table to

reduce the duplication of data and

ensure referential Integrity the

following condition has to be met by the

table to be in third normal form and the

first condition is the table has to be

in second normal form and the second

condition is no non-prime attribute is

transitively dependent on any non-prime

attribute which depends on other

non-prime attributes

I know it's bit confusing so let me make

it simple for you it's like if C is

dependent on B and in turn B is

dependent on a then transitively C is

dependent on a this should not happen in

third normal form all the non-prime

attributes must depend only on the prime

attributes

so these are the two necessary

conditions that needs to be attained so

why was the normal form designed firstly


to eliminate undesirable data anomalies

the next one is to reduce the need for

restructuring over time and finally to

make the data model more informative

since we have understood the third

normal form let's look at the example

table

in the about table student ID determines

subject ID and subject ID determine

subject therefore student ID determine

subject via subject ID this implies that

we have transitive functional dependency

and this table does not satisfy the

third normal form

now in order to achieve the normal form

we need to divide the table as shown

below firstly let's divide the table and

store student ID student name subject ID

and address in it all the columns are

referring to the primary key which is

student ID let the second table have

subject ID and subject column so subject

is dependent only on subject ID and not

on student ID

as you can see from the about table all

the non-key attributes are now fully

functionally dependent only on the

primary key in the first table columns

such as student name subject ID and

address are only dependent on student ID


in the second table subject is only

dependent on subject ID with this being

understood now we can proceed further to

next normal form that is voice code

normal form this is also known as 3.5

normal form it is the higher version of

third normal form and was developed by

Raymond F boys and Edgar F Cod to

address certain types of anomalies which

were not dealt with third normal form

before proceeding to Boy Scout normal

form the table has to satisfy third

normal form in Boyce code normal form if

every functional dependency that is a

implies B then a has to be the Super Key

of that particular table so what is a

Super Key a Super Key is a group of

single or multiple Keys which identifies

rows in a table

let's look at the table to clearly

understand Boyce code normal form in the

given table one student can enroll for

multiple subjects there can be multiple

Professor teaching one subject and for

each subject a professor is assigned to

the student

these are the necessary condition of

this table

in this table all the normal forms are


satisfied except Boy Scout normal form

why as you can see that student ID and

subject form the primary key which means

that the subject column is prime

attribute but there is one more

dependency that is Professor is

depending on subject and while subject

is a prime attribute Professor is a

non-prime attribute which is not allowed

by Boyce called normal form now in order

to satisfy the Boy Scout normal form we

will be dividing the table into two

parts the table at the top will hold

student ID which already exists and we

will create a new column that is

Professor ID and in the second table

which is below will have the columns

Professor ID professor and subject

columns why do we need to have a new

column that is Professor ID by doing

this we are removing the non-prime

attributes functional dependency in the

second table Professor ID will be the

Super Key of that table and remaining

column will be functionally dependent on

it by doing this we are satisfying voice

code normal form

[Music]

what are triggers triggers are the SQL

code that are automatically executed in


response to certain events on a

particular table these are used to

maintain the Integrity of the data in a

given table a trigger in SQL Works

similar to real world trigger I know

this is a formal definition but let's

try to understand it in a better way

here we can see Anna is asking Sharon

about triggers shouldn't imagine trigger

to a falling dominoes how does a falling

Dominos is related to a trigger let's

move further and see the explanation

given by Sharon Anna is a marketing

officer in a company when a new customer

data is entered into the company's

database she has to send the welcome

email to each and every new customer if

it is one or two customer Anna can do it

manually but what if the count is more

than a thousand it will be a repetitive

and tiring job efficiency of Anna may

drop well in such scenario triggers come

in handy Anna can easily create a

trigger which will automatically send a

welcome email to new customer once the

data is entered into the database after

creating a trigger in the database of

the company she doesn't have to monitor

the trigger frequently the efficiency of


the work is increased with this analogy

given by Sharon I hope you're clear with

the introduction of trigger

let's head to the next topic that is

syntax and example of a trigger on the

screen we can see the syntax of a

trigger and let me explain each and

every part in detail the first part is

create trigger these two keywords are

used to specify that a trigger block is

going to be declared the next one is

trigger name it specifies the name of

the trigger trigger name has to be

unique and shouldn't repeat the next one

is before or after this specifies when

the trigger will be executed it tells us

the time at which the trigger is

initiated that is either before ongoing

event or after the ongoing event

before triggers are used to update or

validate record values before they are

saved to the database while after

triggers are used to access Fields

values that are sent by the system and

to affect changes in other records the

records that activate the after trigger

are read only we cannot use after

trigger if we want to update a record

because it will lead to a read-only

error the next part of the syntax is


insert update or delete

these are the DML operations and we can

use either of them in a given trigger

next is on table name we need to mention

the table name on which the trigger is

being applied don't forget to use on

keyword and also make sure the selected

table is present in the database the

next part is for each row or for each

column row level triggers get executed

before or after any column value of a

row changes while column level triggers

get executed before or after the

specified column changes the final part

of the syntax is trigger body it

consists of queries that needs to be

executed when the trigger is called

so this was a brief introduction to

syntax of a trigger

on the screen we can see an example for

a trigger in the given trigger we are

trying to calculate the marks of a

student as soon as his details are

upgraded to the database here we are

adding 100 marks to the marks column of

each new record also make a note new

keyword refers to the row that is

getting affected

so this was all about a simple trigger


but we can also create a nested trigger

that can do multiple process also

handling it and terminating it at the

right time is very important

if we don't end the trigger properly it

may lead to an infinite Loop you might

be wondering in which scenario we can

use the nested trigger rather than

giving you a tailored answer let me

share a scenario with you which will

help you in understanding the nested

trigger in a better way

continuing from the earlier scenario

Anna sent an email for every new

customer that was added to the company's

database now what if she wishes to keep

a track of numbers of customers to whom

the email was sent now Anna needs to

create a nested trigger to keep the drag

of the count along with sending an email

doesn't it sound simple

so that was all about the syntax of

trigger let's now try to implement an

example of trigger in SQL so the next

topic is operations in trigger we can

perform many operations using triggers

some may be simple and some may be

little complex but once if we go through

the query it's easy to understand the

first operation is drop we can use drop


command to remove a trigger from the

database

and the Syntax for this is drop trigger

trigger name to understand this in a

better way let's head to mySQL workbench

I hope you know how to use MySQL

workbench if not then check SQL basics

for beginner video by edureka for better

understanding of how MySQL workbench

will work

to drop a trigger from the database the

trigger has to be present in our

database so this is the syntax used to

drop a trigger so let me execute this

query

so we can see in the status bar the

trigger with the name sample trigger has

been dropped let's head to the next

operation that is display

we can use show command to display the

triggers from the database

and the Syntax for this is show triggers

in database name so let me head back to

mySQL workbench to execute this command

to display a trigger the trigger has to

be present in the database so let me

execute this SQL query to display the

triggers that are present in my database

I can see that the trigger with the name


sample trigger is present in my database

at Eureka so let's head to the next

operation the next operation is insert

and the first variant is before insert

triggers before insert triggers are used

to update or validate record values

before they are saved to database and

the Syntax for this is create trigger

calculate here calculate is the name of

the trigger before insert on the table

name for each row and set operation

so let me head back to mySQL workbench

to execute this query

before explaining before insert trigger

let me explain something else

I will be using student table and The

Columns of this table are

it has student ID first name last name

address City and marks I will be

creating a trigger with the name sample

trigger here before insert trigger is

used to set 100 marks extra for each and

every student marks column when the new

student value is added to the table so

let me execute this trigger

and we can see that the trigger has been

created

now let me insert a record into the

table

I'll be using insert into command to


insert a record into the table

so let me execute this query but before

that make sure to remember I will be

adding details of wamshi K his marks

will be 478 but as we have created a

trigger it has to add 100 marks extra

and the resulting marks has to be 578 so

let me execute this query

okay the query has been inserted so let

me check the table

and we can see that the marks of vamshi

K is 578 so we can clearly say that the

trigger has worked

so the next variant of insert is after

insert triggers

after insert triggers are used to access

Fields values that are set by the system

and to effect changes in other records

and the syntax is create trigger name of

the trigger that is total Mark after

insert on student student is a table

name for each row insert into final

marks value of the column so let's head

back to my SQL workbench to execute this

example

to use this variant we need one more

table that is final marks table where

the trigger will store the results

this SQL query will create a table with


the name final marks so let me execute

this query

so we can see in the status bar the

table with the name final marks has been

created

whenever we insert data to student table

the previous trigger that is sample

trigger will be executed now with the

help of after insert trigger let's show

the marks of the student table in a

final Mark table

this will be the after insert trigger

and the name of this trigger is scal we

will be updating total marks from

student table to final marks table let

me execute this trigger

and we can see that the trigger with the

name Cal has been created to check the

working of a trigger named Cal let me

insert the data of rachit Kumar into

student table and make a note his marks

is 500. so we can see that the data has

been inserted into the student table let

me execute this query

and we can see that the student name

rachit Kumar has 600 marks let's move to

the next topic that is advantage and

disadvantage

let's look at the advantages of a

trigger
first one is forcing security approvals

on the table that are present in the

database the next one is triggers

provide another way to check the

Integrity of the data the third one is

triggers counter react invalid exchanges

the fourth one is triggers handle errors

from the database layer and the final

one is normally triggers can be useful

for inspecting the data changes in the

table

let's look at a disadvantage of a

trigger triggers can only provide

extended validation that is not all kind

of validations for simple validations

you cannot use not null unique check and

foreign key constraints in a given

trigger the next one is triggers may

increase the overhead of a database the

final disadvantage is triggers can be

difficult to troubleshoot because they

execute automatically in the database

this may not be visible to client

applications

[Music]

what are SQL joints so if someone asks

you what are joints in SQL joints in SQL

are commands which are used to combine

rows from two or more tables based on


the related column between those tables

the joints are predominantly used when a

user is trying to extract data from a

table which have one-to-many

relationships between them or money to

many relationships between them joins in

SQL are basically commands guys by which

you can join two tables and you can get

the rows of 2 tables based on a related

column now if you ask me what are the

different types of joints in SQL there

are mainly four types of joints in SQL

that is the inner join the left join the

right join and the full joint so let's

look into each one of them one by one

starting with the inner joint the inner

join is a type of joint that returns

those records which have matching values

in both the tables so if you consider

table a and table B and you apply and

you know join on both these tables then

all those records would be returned

which have matching values in both these

tables so for our understanding I am

going to consider two tables that is the

employee table and the projects table so

when I apply the inner join on the

employee table in the project table all

the steppers which have matching values

in both the tables will be given as


output so the Syntax for inner join is

as you can see on the screen that a

select table one dot column one table

two dot column two table two dot column

one and so on so basically these are the

various columns that you want to

retrieve from the respective tables from

table level 1 in a joint table 2 that is

basically you're applying the inner join

on table 1 and table two and then you

have to mention the related column so

that will be mentioned after the on

statement so you'll mention in a join

table to on table one dot match in

column name is equal to table2.matching

column name so if I have to just repeat

the Syntax for you it's select all the

columns basically whatever columns that

you need from table one in a join table

two on table one dot match column name

equal to table two dot match column name

so if you want to see how in a join can

be applied practically let's move on to

my MySQL workbench where I've created

these two tables that is the employee

table and the projects table and let's

apply the join statements on both these

tables okay so before I move forward

with this let me just open a new query


Tab and let me just clear all the action

outputs so now what I'll do is I'll just

write a statement that is Select star

from employee right so I'll just execute

this particular statement and you'll see

that you know you'll get the output as

all the details from the employee table

that I've already created I have around

five rows with five employee IDs and

their first name last name age email ID

phone number and address faded into this

table so similarly I'll show you the

projects table right so let me just

remove this and let me type in Project

and just execute this particular

statement and you'll see the different

column attributes in the project table

so as you can see I have the project ID

the employee ID the client ID project

name and the project start date client

ID can be basically considered for all

those clients so you can have a separate

table for the client IDs so guys if you

see in both these tables there is a

matching column that is the employee ID

right so the basic relation between both

these tables is that a specific employee

having a specific employee ID can work

on N number of projects right he can

either work on the project number one


two three four five six and so on right

so as you can see my employee ID3 works

on two projects that is the Triple Three

project and the triple four project and

similarly you can see that you know

there are employees with the employee

IDs 978 but yes their information was

not present in the employee table right

so let's apply the join statements on

these tables and understand what we get

as output so initially I had explained

you what the inner joint was so when you

apply inner join and two table you can

clearly see that you know you get

matching values from both the tables so

what I'm going to do is I'm going to

apply inner join on both these tables so

for that you simply have to write a

query so what I'll do is I've already

executed it before I'll just copy and

paste the query over here so that I can

explain it for you guys so what I've

done is I've just selected the employee

ID the employee first name the employee

last name the project ID and the project

name to be retrieved from both the

employee and the project table and then

I've applied an inner join on the

employee in the project table so for


that I've just written a query as you

can see on the screen it's select

employee.mpid

employee.mfname employee.ml name that is

basically the first name and the last

name then project.project ID

project.project name from employee in a

joint project on employee.emp ID is

equal to project.mpid because mpid is

basically a matching column in both the

tables right so let's just execute this

particular query

so when you execute this particular

query you can clearly see that all the

matching values from both the tables

have been retrieved that is basically

all the employees working on a specific

project and their respective employee ID

employee first name last name project ID

and the project name has been retrieved

so guys that was about inner joint now

let's move forward to our next type of

join that is the left join now as you

can see on the screen now the left join

or the left outer join returns all those

records from the left table and also

those records which satisfy a condition

from the right table so if you consider

table a and table b as two tables on

which you want to apply the left join


then table a would be considered as left

table and table B would be considered as

the right table and when you apply a

left join a table a and table B you will

clearly see that you know all the

records from the left table would be

retrieved and also the records with

satisfy a condition from the right table

would also be retrieved also let me tell

you that you know the records which have

no matching values in the right table

the output or the result set will

contain the null values right so

basically if you have around three rows

from the left table which have no

matching request from the right table

then those records will have null values

so the Syntax for left joiners as you

can see in the screen it's just similar

to Inner joint you just have to replace

the word inner joint to left joint you

can change the syntax like you know

select table one dot column one table

two dot column two and so on that is

basically the different column

attributes that you want to retrieve

from table one and then left join table

two on table one dot matching column

name equal to table two dot matching


column name so guys that was about left

join so now let's just again shift back

to my MySQL workbench and then I'll show

you how you can apply the left join I'm

just going to use the similar query so

what I'm going to do is I'm going to

retrieve the first name the last name

the project ID and the project name from

both the employee and the project table

and then apply a left join on it so for

that I've written a query as you can see

on the screen that is Select employee.mp

name employee.mpl name project dot

project ID project.project name from

employee left joint project on

employee.mpid is equal to project.mpid

right so basically that is because you

know this is the matching column between

both the tables so I'm gonna just

execute this particular query so once

you execute this query you can clearly

see the output all the records from the

left table and for those records which

do not have any matching record for the

right table we have a null value present

so if you remember we had five employees

in the employee table right so basically

that was Warden himani ayushi swathi and

famous and if you remember ayushi worked

on two projects so both the project


details are present over here and hey

month worked on no project right so

since he worked on no project the values

present in the project ID and the

project name are null values by D4 so

guys that was about the left join now

let's move forward to the next type of

join that is the right join so the right

join or the right outer join returns all

the records from the right table and

also those records with satisfy a

condition from the left table so I know

all right this sounds quite similar to

the left outer join yes it definitely is

the only difference between both of them

is that you know the right outer join

returns all the records from the right

table and also the records which satisfy

condition from the left table coming to

the left outer chart the left outer

joint returns all the records from the

left table and also those records would

satisfy a condition from the right tip

so it's just wise words of both of them

and also you know the records which have

no matching values in the left table the

output or the result set would contain

the null values so guys that was about

the right join now the syntax of right


join is as you can see in the screen

it's again really similar to the left

join it's simple it's select table one

dot column one table two dot column two

and so on so basically all the column

values from both the tables that you

want to retrieve from table one right

join table two on table one dot matching

column name equal to table two dot

matching column name so the only

difference between syntax if you've seen

the three joints that you saw till now

was the word inner left and right else

everything else would be same so you

just have to apply the same logic so for

that what we'll do is we'll again shift

back to my MySQL workbench now what I'll

do is I'll just copy the query I'll

paste it over here again and then I'll

just change this word to right so I'll

just apply right join

now I'll just execute this query again

so when we execute this query you'll

clearly see that you know the employee

first name last name project ID and

project name are retrieved from both the

tables all those records from the right

table are we retrieved and the records

which satisfy conditions from the left

table are also retrieved but yes those


records which have no matching values

from the left table have null values

present in the record you can clearly

see that you know words in himani ayushi

and Swati worked on projects and then

they had their specific project IDs and

project name but yes they were employees

who worked on project six seven eight

but their employee information was not

present in the employee table so that's

the reason there is null value present

in the records of six seven eight

project so guys that was about right

join now moving forward to a final type

of join that is the full join so the

full join or the full outer join returns

all those records which either have a

matching value in the left table or in

the right table so basically if you

consider table a and table B and you

apply full join on both these table

tables then it will return all those

records which either have the matching

value in table a or in table B now the

Syntax for full join is really simple

it's again the same as the other three

joints but you just have to mention the

word full joint so the syntax is Select

table one dot column one table two dot


column two table two dot column one and

so on basically a different column

attributes from table one full join

table two on table one dot matching

column name equal to table two dot

matching column name so that's basically

again the related column that is

basically a matching column now to see

how full join works let me just shift

back to my MySQL wordpoint now let me

just tell you one thing over here now

since I am showing you how to apply

joints on SQL let me just tell you that

you know on my SQL the full join is not

applicable so that's the reason since

I'm showing you on MySQL workbench the

word full join will not work to just

show you the working of full join I'm

just going to use the word Union in

between both these queries so what's

gonna happen is we're going to retrieve

all the values from the left table and

the matching value to the right table

that is through the left join and then

we're going to Union it with all the

matching values from the right table and

also the values with satisfied condition

from the left table so this is nothing

but full joint but since we're working

on my SQL workbench and the word full


joint doesn't work so I'm going to just

use the word Union I'm just going to

retrieve the project ID the employee

first name and the employee last name so

what I'm going to do is I'm going to

just execute this particular query so

when I execute this particular query

you'll clearly see that you know we're

getting all the values from the left

table which satisfy condition from the

right table and also all the values from

the right table which again satisfy a

condition or match the values from the

left table right so if we consider the

first left joint condition where we got

all the employee details and the project

details you'll see that you know we've

got Warden himani ayushi twice Swati

Haman and the respective project details

since Heyman did not work on any project

the project ID was null over here now

similarly if we consider the output for

the right join where you know we took

all the records from the right table and

took matching values from the left table

we saw that you know for the project ID

is triple six triple seven Triple Eight

there was no employee information

present right so that's the reason we


have null values over here for employee

first name and employed last name so

guys that was about full join so I hope

you've understood the different types of

joints the syntax is really simple for

all the different types of joints guys

you just have to change the word in all

the different types of joints for inner

join you use the word inner for the left

join you use left join for the right you

use the right join and for the full join

you use the word full join so if you

just want to apply left join what you

simply do is you mention all the columns

that is you mentioned the keyword select

and mention the table name dot column

name and then you mentioned from table

one left join table two on and then you

mentioned the matching column names from

both the tables right so you mentioned

table one dot matching column name equal

to table two dot matching column name so

guys that's how you can use the

different types of joints I hope it's

really clear to you guys if you have any

further queries then you can definitely

let us know in the comments section now

that you know the different types of

joints in SQL let me just cover few

important questions that are generally


asked in interviews about joints so the

first question is what is a natural join

and in which situations is a natural

joint used a natural join is also a

joint operation that is used to give an

output based on the columns in both the

tables between which the join operation

is implemented so that's what a natural

join is guys it basically aims to give

you output based on the columns between

which this join is applied now basically

natural join is used when you want to

make sure that you know the number of

columns returned are less so for example

if you see on the screen we have two

tables right that is stable one having

two columns and table two having two

columns over here the table one had

column names column one column two and

table two again has column names column

1 and column three now if you apply a

natural join both these tables you'll

clearly see that you'll get an output as

column one column two column three and

the respective records but in the same

scenario if you apply an inner join what

you will clearly see that you know

you'll get an output like one dot column

one that is basically for table one dot


column one and then one dot column two

that is table one dot column two and

their respective records would be stored

now if you see over here you'll clearly

see that you know when you apply the

inner join you'll have a redundancy of

data that is you know the column one

data is getting repeated again that is

basically it is repeated twice but in

this case of natural join it's just

mentioned once so this was a scenario of

two tables where you know the output was

so simple but yes if you look into a

daily basis where you know database

administrators deal with n number of

tables and then they want to apply the

join operation on these two tables

you'll clearly see that you know if they

apply an inner join then that would

create a lot of problem of redundancy of

data and obviously more number of

columns would be generated but yes in

the same scenario the apply a natural

joint the number of columns would be

reduced at a maximum extent so that's

the situation guys where you apply a

natural joint so if you're ever as you

know in which situations do you apply a

natural joint you can just answer this

question by simply saying that you know


you can apply a natural joint when you

want the number of columns to be less so

I hope I'm clear with this point now

moving on to a second question that is

how to map many to many relationships

using joints now it's a known fact that

you know the joints are basically used

to map one-to-many relationships but yes

if there's a confusion you know how to

map many to many relationships let me

just tell you that you know you need to

use two joint statements so to explain

you why two joint statements are

required you can consider a scenario

when you have creep tables that is the

employee table the projects table and

the Technologies table now let's assume

that you know each employee is working

on a single project so this obviously

means that you know one project cannot

be assigned to more than one employee

now similarly if you consider a project

can be based on multiple Technologies is

and any technology can be used in any

number of projects this kind of

relationship is basically a many-to-many

relationship now to apply the join

operation on the many-to-many

relationships what you can simply do is


you can have three tables that is the

projects table and the Technologies

table itself so basically these are the

two tables which have many too many

relationships between each other and

also we can have an extra table that is

the projected Technologies table now the

projector Technologies table will hold a

combination of project and technology in

every row now let's say we have a

project a let's say this project a has

three technologies that is devops

microservices and Hadoop now you have to

map these Technologies to the project

right now this project to technology

stable will hold the record of every

project technology combination so it

will hold a record of project a to

devops and then project a to again

Hadoop and project a to micro Services

similarly it will have n number of

records for n number of projects and M

number of Technologies so this table is

really really important in this scenario

and this table basically aims to map the

item on the projects table to the items

on the Technologies table so that

multiple projects can be assigned to one

or more Technologies so now that you

have three tables that is the project


table the Technologies and the projects

to Technologies table you need to use

two join statements to link all these

tables together that is use the first

join statement to join the project to

Technologies to project stable and then

we have to use the second join statement

to join the projected technology stable

to technology stable now this is how all

the projects and the Technologies which

have a many-to-many relationships

between them will be linked with each

other so it's really simple guys

whenever you have an end-to-end

relationship between two tables and you

want to apply a join operation between

these two tables you just have to create

another table you know which can have

all the combinations of the previous

table and then you apply a join

operation from table a to table C and

then table B to table C so I hope I'm

clear with this point now let's move

forward with our next question that is

what is a hash join now hash joins are

also a type of joints which are used to

join large tables or an instance where

the user wants most of the join table

rows so whenever the user wants the most


of the join table rows or when you want

to join two large tables you basically

use this type of join that is basically

the hash joint now the hash join

algorithm is basically a two-step

algorithm so it has mainly the build

phase and the probe phase so in the

build phase you basically create an

in-memory hash index on the left side of

input and in the probe phase you go

through the right side of input each row

at a time and then find the matches

using the index created in the build

phase so hash join is again a type of

join which is used to join large tables

and it has mainly two steps that is the

build phase in the probe phase in the

build phase you basically create an

in-memory hash index on the left side of

input and in the probe phase you go

through the right side of input e each

row at a time and find the match using

the index created in the build phase so

guys that was about the hash join now

let's move forward with the next

question that is what is a cell joint

and a cross joint so the self join in

other words is a joint of a table to

itself so this basically means that you

know each row in a table is joined with


itself so when you apply a self join to

a table just remember that you know each

row in a table is joined with itself now

coming to cross joint the cross join is

a type of joint in which a joint Clause

is applied to each row of a table to

every row of the other table so whenever

you apply a cross join two tables then

just remember that you know a joint

Clause is applied to each row of a table

to every row of the other table also

when the where conditions use this type

of joint behaves as an inner join and

when the wear condition is not present

it behaves like a Cartesian product so

you just have to remember two points the

first point is that whenever you apply a

cross join on specific tables a joint

Clause is applied on each row of a

single table to every 0 of the other

table and also when the where condition

is present this type of join behaves as

an inner joint and when the wear

condition is not present it behaves like

a Cartesian product now let's move

forward with a final question that is

how to perform join operation on three

tables now if you remember in the

previous questions I discussed a


question where you know we understood

how to map end-to-end relationships

using join operations right so over

there if you remember we used three

tables that is a project table the

Technologies table and the projected

Technologies table now to apply a join

operation on three tables we use two

joint statements right that is to join

table a to table C and then table B to

table C so basically to apply a join

operation on trade tables you need to

use two joint statements

[Music]

built-in functions are used to calculate

values and manipulate data these

functions can be used anywhere as

Expressions when we say anywhere it

means we can use them in the select

query we can use them in where Clause we

can use them in having Clause so these

built-in functions can be used anywhere

based upon the business requirement of

based upon the type of functions which

we are using so we broadly categorize

the various built-in functions into the

following categories as you can see on

the screen so we can divide the built-in

functions into conversion functions

where we convert the values from one


data type to another data type we have

logical functions math functions to play

around with the data mathematical

operations we generally use math

functions aggregate functions if you

want to calculate for example average we

want to calculate sum or total of a

salary of all employees then we use

aggregate functions string functions

helps us to play around with various

strings or characters in our data most

of the string functions are somewhat

similar to the string functions which we

have in other programming language or

the basic programming languages like c c

plus c sharp or Java date functions have

all the basic functions which we can use

to manipulate date or retrieve date from

our database so let's discuss all of the

functions one by one in coming slides as

we discussed that these are the various

categories again conversion functions

that support data type casting and

converting logical functions are scalar

functions that perform logical

operations these are kind of similar to

the

math functions are again the scalar

functions which performs calculations


usually based on the input values that I

provided as an argument and most of the

times the returns are numeric value

aggregate functions as I mentioned we

use uh some we use average we use

maximum of values so aggregate functions

basically perform a calculation on a set

of values and they return a single value

except for the count so count is also an

aggregate functions other than count all

other aggregate functions ignore null

values in the objective we saw that we

are going to discuss about the group by

and having Clause so aggregate functions

are frequently used with a group by

Clause of the select statement or we can

say that we use Group by class only with

the aggregate functions or group

functions some people refers aggregate

functions as a group functions so don't

get confused they are one and the same

thing

string functions again are scalar

functions and they perform an operations

on a string input value and return

strings or numerical value based upon

the kind of functions which we are using

date function straightforward it

manipulates the dates so let's start

with the conversion functions as the


name itself suggests that it these

functions helps us to convert an

expressions or a value from one data

type to another so we have three

commonly used conversion functions cast

convert and pass and in the bottom three

can you can see that we have try

underscore cast we have try underscore

convert and we have try underscore pass

so the top three and bottom three they

give the same results they work in the

similar sessions the only difference

here is that the top three functions

Returns value of specified data type and

on Success Through errors on failure

whereas the bottom three they give the

null values on failure so we can relate

this try as like how we have the try

cash Block in other programming language

to handle the exception same way we use

trycast if you want to get the null

values if something wrong happened while

calculating the expressions or while

fetching the results same is the case

with try convert and try pass but if any

error happen while using cast convert

and pass we'll get an exceptions I will

get an error whereas error can be

handled by converting it to the null


values if we use try cast try convert

and try pass

so as you can see on the slide we are

converting the value 10 as int and we

are multiplying by 20. again we are

converting int 10 to end and again we

are doing a multiplication of the value

after conversion with 20. so that what

is the difference between cast and

convert because the end result is almost

similar so both function can be used

interchangeably in most of the

situations the only difference is that

cast is NC SQL compliant it follows

American National Standard Institute

whereas convert does not follow any such

compliancing let's see an example of

these basic operation so I'll open

management Studio of SQL let open a new

query and let me copy the example

so let me copy both the examples

I increase the font size

so if I'll execute I'm getting this

result

since we are converting 10 as int and

again if you'll see the result of cast

function and convert functions is

exactly similar only difference is in

the syntax the syntax of convert

function is different from cast function


so one important point I just want to

mention here is that in select operation

we can use mathematical operators like

we can use plus minus divide and

multiplications

so here after converting 10 into end we

are multiplying it with 20 to get the

end result

and this is the Elias which we discussed

in module 2. so we can change it we can

change it to any value we can change it

let's say I'm writing it to cast result

and I can change it to

convert result

if I'll execute it I'll get the same

results cost results and convert result

here are Alias these are the Alias for

the columns in the module 3 we saw that

we use Alias for the table

so let's say that if there's an issue

while casting or converting a desired

value then we'll get an error when we'll

use cast and convert but we'll get a

null value when we'll use tricast and

try convert let's verify this using an

example

so I'm trying to convert character into

int so we'll get an error that

conversion fail when converting the


where care value a to data type int

now let's use trycast

so I'll copy this statement

so let's assume I'll use try convert and

if I'll try to convert a value which is

not numeric and if I'll execute it we'll

get the incorrect syntax near the

keyword try convert sorry I forgot to

write select

and if I'll execute it now

we'll get null value

so instead of error we are getting a

null value if we use try convert or try

cast

So based upon the business requirement

we'll choose either the try converge or

convert

let's move to the next function

let's discuss about the logical

functions

so we have two logical function choose

an F logical functions can be used to

display one of the several values based

on a logical conditions so as we have

discussed we have two logical functions

choose an if choose returns a specified

index from a list of values and returns

null if the index is 0 or greater than

the number of items

or we can say that the choose basically


act as index into an array when an array

is composed of the argument that follow

the index argument so as you can see the

Instinct syntax we have the choose

keyword and in the parenthesis we have

index so this is the index which we have

to Define that what value we want to

return and this value 1 value 2 and we

can have up to Value n so let's

understand choose by an example

so

let me write one example so that it will

help us to understand

choose keywords and all these functions

are basically uh can you see the color

code for the keywords we basically have

blue colors but for these functions we

have pink color

so we'll Define

3 this is the index

and Then followed by the various values

let's say I have test as a one value I

have

just as another value

third value I'll be having

rest

so if I'll execute this statement

I should get the value rest because this

index does not start with zero please


note it down either choose a function

the index start from 1 this is one base

index not the zero base index like we

have in most programming languages so if

I'll execute this statement

I'll get rest because we are instructing

the SQL Server that we want the third

value after the various values available

so choose function basically gives an

error if you try to use the index as the

value 0 or we'll try to provide the

index which is outside this range so

let's understand it by an example

so if I provide a index 0

if I execute this I'll get a null value

or if I'll provide the index which is

outside the bound of this array when I

say bound if it is more than the number

of values which we are trying to select

from then again it will return signal

value so this since there are only four

values here and I'm giving index 5 so

since there's no value at the fifth

index it will return an L it won't give

us zero so choose functions helps us to

select from a given range of values like

how we used to fetch the values from an

array so let's discuss the other logical

function so here before we discuss the F

let's see these examples as well so in


the first example we are using select

choose and we are giving index to a b

and c these are the three values so this

will the first example will return the

value p in the result set because we'll

count from the index 1 as I mentioned

the choose is based on one index and not

the zero index so let's take the case of

the second example here we have not

provided an integer we provide a

fraction value 1.4 so choose only

consider the integer value in both the

cases it will return a s in the result

set so now let's discuss the other

logical function f so let's focus on the

syntax first so it's followed by if

keyword and then we have a Boolean

expression and then True Values and

false values so when we execute this

function it returns one of the two

values either it will return true value

or either it will return false value

so the output whether it is true or

false depend upon the evaluation of

Boolean Expressions which will provide

in the IF function so if is a shorthand

way of writing a case expression it

evaluates the Boolean expression pass as

the first argument and then returns


either of the two argument based on the

results of the evolution so we can even

provide the nesting in the if functions

the nesting should be up to 10 level

similar to the nesting which we can have

in the case expression as it is almost

similar to the case expression so let's

see or discuss the example of if logical

function so in this case it will written

false because this Boolean Expressions

is not satisfying one is not greater

than 10 so it will fetch the result

false in the result set let's execute

this example in management Studio

so let's write if

if

then you have to write the Boolean

expression

then any value let's say I'm just

writing true and the next value if it

turns out to be false

let's see example

yeah the example seems to be right

let me copy from here

okay so we forgot to add the select

keywords it's all about that and if I'll

execute it will return the false so

since there is no header for the column

name we can provide an alias as well

if I'll make this statement as true if I


if I'll reverse the values here

then I will get true as an output in my

result set

so as I mentioned if works like a case

expression and we can Nest it and

nesting can be allowed up to 10 level so

this is all about logical functions so

let's continue with other categories of

functions so let's discuss about the

math functions so math functions can be

used to calculate business and

Engineering calculations so these are

various self-explanatory and we must

have used these functions during our

engineering classes or any other classes

where we do any engineering calculation

for example when we convert it to an

absolute positive value then we use ABS

functions if we want to generate a sudo

random slot values from 0 to 1 then we

use rank function seat is an optional

value here if you want to return an

exponential value then we use exp

function in most of the mathematical

values we need to round up the values

when the values are of decimal then we

use round functions so round Returns the

numerical value rounded to a specific

length of precisions that we need to


provide in the functions floor provides

or it Returns the largest integer less

than or equals to the specified

numerical Express iterations then we

have square root square root Returns the

square root of the specified float value

ceiling is just opposite of the flow and

it Returns the smallest integer greater

than or equal to the specified numeric

expression Square again and as we know

the square square of 2 is 4 so like we

use the square functions to calculate

the square of the specified float value

power power basically Returns the value

of the specified expression to the

specified power so these are the

standard mathematical functions we have

used these functions so here we can see

a Consolidated examples of all

mathematical functions so in the first

example we see select ABS minus 10. so

here we are using absolute value so it

is converting the negative values to the

positive value and all these keywords

are we are using as LDL so we are using

abs's Alias for the First Column run as

we discussed run is basically helps us

to uh get any random values we can

provide the seed see it is optional when

we use these functions so as you can see


we are getting a random value here exp 4

it basically helps us to get the

exponential value flow we use flow so it

will get the value 4.66 will get the

value 4 here so flow we will get the

value less than the nearest integer in

the ceiling will get the values greater

than the nearest integer so if I'll use

flow 4.66 I am getting the value 4 when

I'm using ceiling I am getting value 5

here square root the square root of 2.56

is 1.6 so this is the value we are

getting square is just opposite to the

square root so we'll get the square of a

digit which will provide in the

parenthesis so we have provided a value

4 so we are getting 16 as its result

power 2 3 so we are basically giving

power 3 the base value here is the 2 and

3 is its exponential value to the power

3 will get 8 it's it's Statesman if you

want to expand this it's 2 into 2 into 2

so we are getting 8 as its results round

function is basically is to round the

values and we are using 2 as a Precision

value so we have provided so it is

basically rounded up to 2.57 so let's

execute few of the examples in

management studio for better Clarity


let's use the square function and square

root function first

the square root of 16

and always use the select statement or

else we'll get an error

so I can even do like multiplications of

various uh I can use various

mathematical functions and then I can

multiply it or I can use other operators

like plus minus

so if I'll execute this so what I'm

doing is I'm taking the square root of

16 that will be 4 taking Square 4 that

is 16 so end result should be 64. yep so

we get the result as you can see guys

when we don't give the name of the

column the header is blank so it is good

practice to provide the alias

as of now I am giving a standard keyword

visual set if I'll execute it now I'll

get 64 instance value

I can even use other mathematical

operator

I can use plus so to provide the sum of

these two values 16 plus 420 so we'll

get 20 in the result sets

I'm getting minus 12 its value and let's

see can we collect functions here so let

me write select and if I use apps

function here
so now I should be getting plus 12

because I'm using absolute function so

it will convert the negative value into

positive values so we can use we can

club we can Nest the functions

so here in the apps functions I'm using

sqrt functions and square functions we

can play around with these functions as

per our business requirement

let's use an example of power

let's let's use the base value S2 and 2

to power 4 so the result will be 16 so

this is equivalent to

sorry

if I'll expand this power 2 is the base

and 4 is the exponential so I'll get the

same results at 16. so this is all about

the maths functions let's move to

another category

ignose null values aggregate functions

are frequently used with the group by

clause and for a filtering like we used

to filter the data using where Clause so

if you are using Group by Clause then we

use having keyword to filter the result

set so we have a following aggregate

functions we have average main sum count

and Max so let's start with average

function first so average Returns the


average of the values in a group as we

discuss null values are ignore so let's

take an example of average function

first let me fetch the values from

Department table

okay so I I can use the average

functions on department number column

so I can write select

average I'll write the column number

from Department

if I execute this

I'll get the average of the values so

let me execute both the queries in Funko

so we can compare the results so 25 is

the average of

40 plus 30 plus 20 10 divided by 4.

so we can use average functions with a

distinct keyword we we discuss about the

district keyword in module two so

distinct keyword helps us to fetch the

unique records so if you want to find

the average of the distinct values then

we'll provide the distinct keyword

before the column name

so let's take another example of the

average function let me get the results

from employee table

so as we discussed that average

functions ignores the null values so if

I try to get the average of salaries so


we have only three rows where the

salaries present rest all the values are

null let's see what is the result

select

average

I'll provide the name of the column

from employee

so this is the average

so let me execute both the statement in

Funko like I did earlier so you're

getting the average of this

so we can use average with the distinct

keywords if you want to fetch the

results okay let's see whether we can

apply the district here so in the

department one table we have the

repeated values for the Department

number so if I want to ignore the

repeated or redundant data or the

duplicate data then I can use the

distinct keyword so if I execute it now

I'll get the average s25 but if I'll

remove the distinct keyword

the result sets will be different

sorry my balance I'm using Department

column I have to change it to Department

one so let's first see the result set

without using the distinct keyword the

results is 30. now I'll use the keyword


distinct

so the value is different because I'm

just taking the unique values for my

result set

so let's move to another aggregate

function let's discuss the main function

similar to average Min also ignores the

null value and it Returns the minimum

value in the expression

so if we'll see the values in the

department one table and if I try to

find the lowest value of the department

number then I have to use the Min

function

okay so out of all the aggregate

functions count is the only one which

considers which takes into account the

null values as well

so let's see the example of count

let's move to management Studio

so

I'll be using employee table because we

have lot of null values in those

like secret this so let's take the count

of the salary column

select

count

I have to write the

column name

employee
so if I'll execute I'll get three

results

but if I execute

star

I'll get nine columns

so even we can use the distinct

operation here

in the count function

so count basically fetch the count of

rows from a table

so let's move to another aggregate

function we have Max so max is exactly

opposite of Min we have already shown

example of minimum so max we can use it

for numeric as well as with the

character data type if we use for the

character data type it will show the

maximum value in the Sorting order if

you use with the numeric then of course

it will show the maximum of the value

though let's see an example of Max as

well so if I'll use

Max

we're trying to find the maximum salary

from employee table

so this is the maximum salary

and if I try to find

the location let me first show you the

various location from the Department


table

so as per the Sorting order we should

get Hyderabad if if we'll use max for

this column

so let me write the query

select

Max

Loc

from Department table

and we can provide an aliens as

location

so I'll get Hyderabad in my result

so we have discussed all aggregate

functions so the common aggregate

functions are average if you get the

average of values Min as name suggests

the minimum value in the expression sum

helps us in finding of the total for a

column sum only accepts the numeric

value count Returns the number of items

or rows in a group or in a table Max

returns a maximum value in the

expression

so let's move to other category of

functions

so these are the various examples before

mu to other functions let's read the

examples here so in one example we've

shown all the aggregate functions so we

can use multiple aggregate functions in


the single statement a single select

statement so in the single select

statement we have used average of salary

minimum of salary maximum of salary and

sum of salary from employee table second

example is for the count functions so we

will discuss about the group functions

and having functions once we are done

with uh most of the out of box functions

then we have string functions

string functions are against scalar

functions and they perform an operations

on a string input value and the return

string or numeric value based upon the

type of functions which we are using

when string functions are passed

arguments that are not string values the

input type is implicitly converted to a

text data type so these are the various

string functions L frame it basically

returns a character Expressions after it

removes leading blanks it basically

removes the blanks from the left hand

side of the string we have R frame it

Returns the character string after

trinketing all the trailing blanks

basically it remove the blank from the

right hand side of a string care

functions converts an INT asci code to a


character character index find out and

ex searches and expressions for another

expressions and returns its starting

positions if found Str returns character

data converted from numeric data concat

written a string that is results of con

connecting two or more string values so

these functions are almost similar to

other string functions which we use in

other programming languages so most of

the programming languages we have trim

functions we have uh functions to find

out the index of a character we use

concanity operation this is a very

common uh string functions to con

connect two strings or more than two

strings then we have replace functions

so replace all occurrence of a specified

string value with another specific value

we have substring it Returns part of a

character or text based upon the length

or the start index which we give in as

we can see in the syntax of the

substring we have a substring a keyword

followed by the expression like the

string from which we want to find out

the part of a character we'll Define the

start index and then we'll Define the

length from start index till how many

characters we want to fetch the


substring then we we have the format

functions we can format strings in the

desired format using the culture then we

have left functions it Returns the left

part of a character string the opposite

of left is the right functions which

Returns the right part of a character

string reverse return the reverse order

of a string value upper functions

converts the string into uppercase

a positive which is the lower functions

which converts the Expressions into

lower case

and in the end we have length function

or Len which basically Returns the

number of characters of the specified

string and it exclude the trailing

blanks

so these are the various examples on our

slide so first one is for the replace

function so this is our string and this

is string we are replacing CDE with XXX

as a replace so as you can see in the

result set here for the replace column

the value c d e is replaced with triple

we have substring functions in the

substring we are get out of this A B C D

E F which is our main string from index


to

and till length 3 we are getting the

substring so index 2 is start from B and

then up to three character we'll get the

substring so we'll get b c and d in our

output then we have left so it basically

written the left from a character index

so from index 2 we are getting the

values from the left so it is a and b

from the right we are getting the value

of b c d so in the end we have the

examples of date and time and format

so here we have provided the various uh

cultural values so first is for our U.S

English Second is for British English

and third is for the German So based

upon the info culture we basically get

the different results here so most of

the string functions are pretty much

straightforward so let's discuss about

few of them so we'll discuss about a

reverse

so I'm adding a string a b c

again I forgot about the select

statement this will give me an error if

I'll try to execute this statement

without select and if I'll execute it

now I'll get the reverse of the string

always good

to provide alias
then we have trim or L train

select L frame

so I have added uh leading blank spaces

in this string and if I'll execute this

the leading spaces has been trimmed same

way I can use R trim

so if I'll use R frame then only the

trailing spaces will be removed not the

leading one if I'll execute this I'll

get this result

and if I'll use stream that will

consider for both

we do not have trim here

so L dream removes the leading spaces

and R frame removes the filling spaces

so this is all about the string

functions you can practice about the

other string functions they are pretty

much straightforwards let's let's see an

example for the upper and lower

functions as well

so if I use lower here

I'll get the same result but if I'll use

or let me convert

let me first write the uppercase

character so it's convert into lowercase

and if I'll write the lowercase

if I'll use the upper function

hit convert it into uppercase


so all other streaming functions are

also self explanatory

please try all of them so that you will

have an idea and if you will trial all

of these you you will come to know that

if the situation size you can start

using those so let's move to other

functions the date and time functions so

date and time functions are again scalar

functions that performs an operations on

a date and time input value and retains

either a string numeric or date and time

value so as you can see in the screen

there are various date and time

functions again we have says date time

it returns a date time value that

contains the date and time its current

timestamp against return a date time

value that contains the date and time

date part basically fetch as the date

part of a date component day month year

returns an integer that represents the

day month and year part of the specific

date if Returns the number of date or

time date part boundaries that are

crossed between two specific dates and

date 8 functions returns a new date time

values by adding an interval to the

specific date part so let's see the

examples of date and time functions


this date time it Returns the system

date times it has date component as well

as the time component current timestamp

also gives the current date and time

date part basically provides if it will

provide ER here then it is providing the

year of the date part if I'll provide

here the DD it provides the day it will

provide mm it will provide a fresh

delivery value of the month date

difference so again if we are providing

mm so we are getting the difference of

month between these two dates if I'll

provide DD then it will provide me the

difference of days between the two dates

so date add is that I am adding two

months so this is how we have to do

since we have provided mmm specify for

month here if I'll provide the DD then

it will add two days since we have

provided mm here so it will add two

months to the current rate so let's see

one example here

date part

here

let's say mm and then we can provide the

date

this

wearing the month so 12 months since I'm


using December

if I change it to October

and if I'll execute again it will show

me that value 10. so this is how we use

the date part and let's see the dated

function

so if I execute it now it will add two

months I can also provide DD here

it's like two days

so this is all about the date functions

so now let's discuss about the group by

clause and having clause

so as you can see we are using Group by

keyword here and we are using having

keyword here so let's discuss about the

group by and having clause

let's discuss Group by first the SQL

Group by Clause is used along with the

group functions to retrieve data grouped

according to one or more columns the

important part here is that the group by

Clause should contain all the columns in

the select list except those used along

with the group functions so let's see an

example of group by functions for better

understanding let's move to management

Studio

and we will use Department one table for

group by

clause
let me first execute this query

so what I'm going to do I'm going to

group by the department number so I'll

find select

count of rows

from Department one

then I'll use Group by keyword and I

want to group the data by Department

number

so can you see it's grouped or even I

can write

the department number

and let me write the Alias for this

and I'm writing the areas here as

Department number

if I'll execute this I'll get so we have

count four for the department number

there are four values for the Department

Number 20 same way five values for

department number 35 values of 40 one

values for department number 50 and one

value for department number 80. so we

use Group by functions generally in

association with aggregate functions so

it helps us in grouping the data in a

table the important part here is that we

have to use all the columns in the group

by which are there in a select statement

so if if I'll try to include location


here there's one more column locations

in the department one table but if I try

to execute it now I'll get an error

because all the columns other than the

aggregate functions should be there in

the group by clause

so if I'll include the other table as

well then the query will be executed

successfully

so to in order to execute Group by

successfully we have to include all the

columns which we are including the

select statement in the group by clause

and also we can include multiple columns

in the group by Clause it is not that we

have to use only the single column so

Group by helps us to group the data in a

single table and it is generally used

along with other aggregate functions so

let's see the example so here we are

basically again uh grouping by the

department number here

so let me fetch the results from the

employee table

so here we can group the records again

using the department number

or using the job ID

so file to use for the employee table

I'll write select

job ID job underscore ID and then again


I can use for example let's say count

it's not that we have to always use the

counter aggregate function we can use

other aggregate functions also

from employee

and then I'll write

Group by

job ID

so this will group the data according to

the job so only for a job ID 7 we have

two rows

for all other job IDs we have a single

room

so we are clear with the group by

now let's discuss with

let's discuss the having a keyword

so the having Clause was added to SQL

because the where keyword could not be

used with the aggregate function we

cannot use a where keyword with this

aggregate function so having applies to

the summarized group records whereas

where applies to the individual records

so if it is a summarized record or the

group we use Group by then we have to

use having and if it is the individual

records then we'll use the where clause

so if we'll use the having close only

the groups that meets the having


criteria will be returned in the result

sets

and having keyword requires that we'll

use Group by in our SQL query

so we can say that the having Clause is

used in combination with the group by

Clause to restrict the group of written

rows to only those who whether to only

those which is matching the conditions

or where the conditions is true

so let's see an example so here in this

example we are selecting the department

number taking the average salary minimum

salary and the maximum salary and and we

are finding that if the having the sum

of the salary is greater than 3 000

touches only those results

so let's write uh let's see this example

in the management Studio

and I can write here

having

salary greater than let's say 30 000.

oh we have to include the

where the minimum salary you have to use

the aggregate functions in the having

clause

yeah so we get only two results

so let me first show you the result sets

so we have uh three rows which are

having the value for the salary column


j4 having salary of 40 000 J5 is blank

so we have j6 as 500 000 and then we

have J1 as 30k so as per our query we

should get only the two results that is

j4 and j6 because these are the only two

rows which are satisfying the having

Clause so having is kind of we used to

filter the result sets but with the

aggregate functions we cannot use where

command so we are supposed to use having

Clause so this is it about the various

after box SQL functions

and first we will discuss about the

store processor a stored processor is a

set of SQL statements with a name that

has been created and stored in the

database

so when the execute or when we write SQL

statement but we are not storing those

queries but in store procedure we can

write a set of SQL statements and we can

you know execute them and they can store

it in a server so every time I don't

have to write SQL queries I can write my

business logic in the store browser so

stored procedures can be defined as a

set of logical group of SQL statements

which are grouped to perform a specific

task
so basically in stored processor we

write most of our business logic

it's like other programming languages

stored processors accepts input

parameters they return multiple values

by means of out parameters or output

parameters they contains programming

statements a store processor can call

other store procedures or functions a

written status to indicate success or

failure

let's see the syntax of stored processor

first so this is the syntax we have

create keyword to create a store

procedure we have to write create

followed by a keyword procedure name of

the store processor which we want to

create

you want to provide any parameter in the

store processor then will provide the

parameter name

if you want to create the parameter as

the output parameter then we have to use

the keyword out or output followed by as

keyword and we'll write begin and

whatever the statement or competitions

we want we'll write that and in the end

we have to write end keyword so in the

syntax it is mentioned that it is create

or alter so if we want to modify the


existing stored procedure then we have

to use the keyword alter if we are

creating the support as a first time

then we have to use the keyword create

so alter keyword is used if you want to

modify any existing store processor now

why we create store processor when we

can write SQL queries so here are the

some of the benefits of creating stored

procedure all commands in a stored

processor are executed as a single batch

of code when we execute queries in SQL

generally each query goes as a single

batch but when we execute store

processor though it may have multiple

SQL statement all SQL statement are

executed as a single batch of code so by

doing this it reduced the server or

client Network traffic and improves the

performance

store process helps us in achieving

strong Security in SQL because we can

impersonate another user execute as can

be specified to enable impersonating

another user to perform certain database

tasks without providing direct

permissions to the processor

so it makes our environment more secure

reuse of code
store process helps us in achieving

reusability because as we discussed in

the previous slides that we can call

another functions or store process from

one store processor easier maintenance

changes need to be done within the store

processor which handles all DB

operations and no changes are required

in client applications

so sometimes we move our business logic

to the store procedure

so if any changes are required we need

to modify our business logic then we

don't have to change our client

applications or our code we have to just

modify the store process and execute it

again

also if there is any error we know where

exactly to look for and we have to debug

only one store process instead of

looking for multiple SQL statements that

is the reason store process are easier

to maintain

improved performance

all procedures by default are compiled

in the database the first time it is

executed and it maintains the execution

plan for subsequent calls so if we'll

execute or it will call or run the store

process again it will take less time


because it is already compiled in that

database the very first time so by doing

this the performance of applications has

increased so on this slide we can see of

an example of stored procedure so we're

creating a store processor so we have

writing our first the create keyword

followed by the procedure SP underscore

git employee info is the name of the

store processor this store processor we

are passing a parameter employee ID

whose data type is end

followed by the basic syntax we are

defining the keyword as in begin and

then we are writing the basic query that

select employee ID first name last name

manager ID phone number High date job ID

these are The Columns of table employee

and then we are passing the condition we

are filtering the records from employee

table by using a where clause and in the

where Clause we are not hard coding any

value we are equating it with an

employee ID which is the parameter so

when we will execute the store processor

we will pass the parameter

so let's see if you example of the store

procedure so let me open management

Studio
so let me open the examples I've already

have

so let's create a store process without

parameter first

it is not that every time when we create

a store processor we have to define a

parameter

so I'm writing the create keyword

followed by the procedure and all result

keyword will be highlighted in the blue

color now importing a name of the store

processor so I can provide any name here

so I'm providing uh get details

or I can mention it to give it more

meaning get Department details and the

store projects I have simply written a

one select query that selects star from

Department

execute this query command completed

successfully means we have successfully

created the store browser in database

now where to check for the store

processor so I'll first expand the

database under which I am creating the

store process

uh important thing guys is that we have

to use the database first that under

which database we want to create our

store browser so always write the name

of the database use keyword followed by


a GO Keyboard

now if we'll try to execute this

statement again I'll get an error that

this is already an object name USB get

Department details in the database so

since I've already created this store

processor I will try to create it again

it will give an error so when you

provide a name of the store processor

please ensure or please check that this

the name which you are providing is

unique and it does not exist in the

database in which you are creating that

stored process so if I want to check

where exactly the stored browser has

been created I have to expand the

programmability folder under program

empty folder we have a separate folder

for the store processors Let me refresh

it

so here we can see the store browser dbo

USB get Department details so from this

object Explorer I can modify the store

procedure I can execute the store

processor or even I can delete it so to

delete it we have to Simply click delete

here it will again reconfirm whether we

actually want to delete this store

browser and if there are any dependency


of the store processor we can check it

with the show dependency so when we

delete something from our database it is

better to check the dependence if there

are independency we rather not delete

that particular object so as of now we

know that there's no dependency so I'm

just clicking OK here and it will delete

the store browser since we have deleted

the store processor and now if I'll

execute this statement again it will be

executed successfully as there was no

store process in a database and by

execution the statement will again

create the store processor so if I

refresh this store browser again I'll

see the stored process

now we have created the store processor

and we'll see how we can execute this

store processor

to execute the store processor we have

to write one command

so there are various keywords which we

can use to run this store processor

the first one is we have to write this

keyword

exec followed by the name of the store

processor so if I'll execute this it

will execute the store processor and it

will return this query or this result


set because in the store processor we

have given only one select statement

that selects start from department and

the department table has three columns

so we are getting all the rows because

we have not specified any where

condition so this is an example of a

store processor without a parameter

since the stored processor doesn't have

any parameter we are not passing any

parameter while executing this stored

procedure so it is not mandatory to

provide the exec keyword while executing

the store browser even if it will

provide the name of the store browser

and if you'll execute it it will fetch

the same results

so exec keyword or execute keyword is

optional while executing the store

processor so let me again delete this

store procedure

so while creating the store browser

again we can either provide the create

processor or we can even provide the

short form that create proc even if I'll

execute this statement it will be

executed successfully and if I'll

refresh this node we can see the store

browser has been created successfully


while executing again it is optional

provide the execute keyword similarly

while creating the store browser we can

either provide create proc or create

processor now let's see how we can

create a store processor with a

parameter

so I'm opening a new query window and

press the font size for better

visibility

so this is an example of store processor

with the parameter

so here we are providing the parameter

Department number

so here we have department number as a

parameter and the data type of this

parameter is n worker and length is 30.

so in the previous example we have

written as select statement but without

the where Clause here I am providing or

I am filtering the record or rows by

using where clause and the where Clause

I am checking the depart number with the

parameter which will pass while

executing the store procedure so let me

create the store browser first and then

we will execute it the command completed

successfully means the store browser has

been created successfully so let's again

refresh this node


yeah so now when we are executing this

stored processor even like as we saw

that we can provide the execute keyword

or we can even directly write the name

of the store browser or if you are using

the management Studio we can right click

the store processor and then we can

click execute store processor so the

execute store browser will open this

window and if there are any parameter it

will pass it will check whether what

value we want to pass to this particular

parameter as we know that we have

various values of department number

start from 10 to 80. so I am passing 20

as a value for the department number and

I will click ok

the moment I'll click ok I'll get this

result

so an earlier example we got all the

rows in the result set so if we do not

want to execute the store processor from

the object Explorer then again we have

to write the same command we have

execute keywords followed by the name of

the store processor

and then we'll pass the parameter

in our case the parameter is Department

number
so now this will give the desired result

so this is how we create store processor

with parameter and this is how we

execute the stool processor

which has a parameter in it now if you

try to execute this store browser

without providing the parameter now

let's see what happens

see you will receive an error the

procedure or function USB get detail

expect parameters which was not supplied

it means when we created the store

processor we have ensured that the

parameter which we are providing in

Azure browser is mandatory why because

we have not explicitly or defined that

this parameter can accept null value as

well so if we want to make the parameter

null then we have to explicitly provide

the null keyboard so let me modify this

store process or let me first delete

this store process and will recreate it

again so I'm just deleting the store

processor

and in order to make our parameter

optional instead of monetary we have to

provide the keyboard null and I'll

execute the statement again to create

the store browser now if I'll execute

this store processor you won't receive


an error but we won't get the value

because we are checking the null value

and if I are not provided in null so it

will not return any result but yes the

error is gone

so this is how we make the parameter

optional by providing the null keyboard

now let's see how we can create a store

browser with multiple parameters or is

it possible to create a store browser

with multiple parameters yes it is very

much possible to create a stored

processor which accepts multiple

parameters so let's see it with an

example let me open a new query again

and we already have an example handy

with us

let me paste it in management Studio

so we have this stored procedure and

here in this store processor we have

defined two parameters one is department

number and Department name

we have make both of these uh parameters

as optional by providing the null

keyboard so if you want to create or do

you want to Define multiple parameters

in the store processor all we have to do

is that we have to separate the two

parameters with a comma that's it


rest everything is same we have to

provide an as keyword after the

parameters and then we'll write the

student body in here we are again

writing a select statement but we are

adding a where Clause to filter the

result sets by providing two conditions

and we are using logical operator that

is end

to combine two conditions

so let me execute uh these statements to

create a new store process with multiple

parameters

the store person has been created

successfully we'll refresh this node

and this is the stored browser

so let me first see the data in our

table so that we can provide the right

parameters values to get the values in

the result set

okay so I'll pass the parameter

department number as 50. and Department

name as ID so all I have to do is I have

to provide the keyword execute

name of the store processor

get get details from

then we have to provide the value for

first parameter that is Department

number

its value so we have decided to pass its


value as a 50 and then we'll provide the

value for another parameter

since it is string we have to enclose it

is a single quotation and now I'll

execute this and we'll get the desired

result that department name is ID and

it's located in Mumbai so this is how

we'll execute and the stored processor

with multiple parameters so we write the

name of the store processor and follow

the first parameter then write a comma

and then the second parameter and so on

a parameters also in other store cursor

if you want to execute it from the

object Explorer then you have to right

click the store browser and click

execute store processor and get both the

names we'll pass the value here and

we'll click OK if I'll click it okay now

though there won't be any result in the

results then but it won't throw any

error because while creating the store

browser we have defined that these two

parameters can accept null value so they

are not mandatory these are optional

that is the reason even though we will

provide any value we won't receive one

while executing the store processor

now let's discuss about the output


parameter in the store processor

so if we want to return the value of the

parameter then we have to Define an

extra keyword that is out or output both

keywords are valid whether we use out or

output against the name of the parameter

whose value we want to return so let's

see it with an example

so I'll open a new query in the store

procedure I have two parameters one is

the department number and one is count

so we have defined a keyword output

which suggests that this parameter will

be the output parameter so we can pass

the value this to this parameter and

this parameter will also return the

value after execution so we can provide

the keyword output or out there's no

difference the end result will be the

same

stored is created will refresh the node

of the store processor to see the

results

yep we have the store person now in

order to execute this we have to do like

this

we have to first declare the count end

followed by the executive name in the

store processor will provide the value

this is how we have to Define if it is


an output parameter and then we are

writing the select statement to see the

value of the count so let me execute

this so the count is 1 because there is

only one row with the Department number

10.

so this is how we use the output or out

keyword

against the parameter

now let's see how we can add comments in

the store process

so we can add the comments

in two ways one is the line comment

and one is block comments

so if you need to provide the line

comments

then we have to use two dash followed by

statement

and in order to forward slash and then

stop

in this writing this is multi-parameter

stored processor

having

output parameter

again we write star and a forward slash

so this is how we Define the comments in

a stored process not in the stored

process we can write or Define the

comments anywhere in our SQL queries


whether it is a functions or normal SQL

statements or it is a stored processor

so line comments or single line we use

two dash and for Block commands we use

forward slash and star

so let's see how we can handle the

exception in the store processors

so if you have handled the exceptions in

your programming languages like C C plus

plus or like Java or C sharp

then we use try cache there

and along with trackhead sometimes we

use finally block because finally always

execute so if you want to close some

like we want to close some connections

or we want that some statement to

execute no matter whether there's

exception or not then we write those

statements in the final block so we do

not have any final Block in the store

browser or SQL which have let's see how

we can Define the try and catch blocks

in store processor with an example

that we first increase the font size I

am creating this store processor with

the name dbo USB try catch test

and to write a catch blog we have to

provide the syntax begin try then in the

body we'll write whatever the statement

we want to write and then followed by


the Android so n try basically ends the

try block

after that we'll provide begin catch and

in the catch and see what we are doing

here is that we have written a select

statement that we are providing what is

the error number what is the severity of

this error what is the state processor

in which line the error is encounter and

the error message so let's create the

store process first

and then we'll refresh this node so we

have this load process and now uh the

store Professor did not have any

parameter so I'll execute this tool

processor

execute keyword

followed by the name of the stroll

processor

no parameters so we are not passing any

parameters while executing it

and see since we are dividing by 0 it

will give an error it will results in

infinity and see since it will go to the

catch block since error has encountered

so we have written the statement in the

try block so in the catch we are

handling the exception and while

handling the exception we have written a


select statement which provide all these

values so the error number is at one

three four error severity 16 so these

are the you know predefined severity

levels so we can check on Google said

what the severity error severity 16

means

then we have error state in which

processor the error has occurred so it

will give you the name of the procedure

the name of the processor is USB try

cache test

Airline S4 and the error message that we

are dividing by uh 0 so we'll get the

message that divide by zero error and

counter so this is how we mentioned try

catch Block in the store processor we

have seen various examples of the store

processor so we have created the store

browser without parameter with parameter

we have create a store process with

multiple parameters we have seen that

how we can you know include comments in

the stored process using single line

comments or block comments and we have

seen that how we can handle the

execution the store preserve so this

exception handling is not only for the

store processor we can handle this

exceptions in functions as well so we


can write try block and followed by a

catch Block in the cache block again we

can write the select statement to show

the message that where exactly what is

the CVT level what is the error message

we can even provide the custom error

messages up to us so let's move to the

next topic so I hope you are cleared

with the concept of store processor in

SQL let's move to the next topic the

next topic is user defined functions so

though SQL Server provides list of many

predefined functions that are built into

the T SQL language these supplied or out

of box functions helps in extending the

capabilities of SQL by providing the

ability to perform like string

manipulations mathematical calculations

data type conversions by using converter

cost functions

Etc but sometimes these out of box

functions or inbuilt functions are not

enough and there are certain

functionalities which is not provided by

these functions

so this issue can be easily addressed if

we can create some user defined function

so like functions in programming

language and all programming language we


write functions

there are some functions which do not

return any values they are functions

which returns a value and we pass

parameters we do not pass parameters

while you know calling the functions

so user defined functions in SQL are

almost on this same lines of the

functions in other programming languages

so user defined functions are compact

piece of transact SQL code which can

accept parameters like how we pass the

parameters in store points the same way

functions can also accept parameters

functions can perform complex

calculations and written either a value

or a table

so this return type is basically based

upon what kind of functions we are

creating or executing

so let's discuss what are the various uh

benefits of user defined functions so

again like store processor functions

also helps us in achieving the concept

of reusability

it will prevent us from writing same

logic multiple times we can dump a set

of SQL statement in a function and then

we can call it as many as times

like store process they also improve the


performance because the user defined

function reduce the compilation time of

SQL query by caching the execution plan

and reusing it

functions are also easier to maintain

because functions help us to separate

the complex calculations or the complex

business logic from the regular SQL

query so that we can understand and

debug the query quicker and better

it again reduce the network traffic

because of its caching plan

functions again can be used in where

Clause as well by this we can limit the

number of rows sent to the client so we

can use functions in select clause and

we can use the functions in where clause

now let's discuss about the structure of

the functions user defined functions are

composed of two parts one is header and

one is function body we'll see in

awesome examples that how we create

functions so the header contains the

function name input parameters if there

are any input parameters because again

the parameters are optional but in the

store processor or whether it is a user

defined function along with parameter we

have a written parameter info its name


and type in the header section the

function body contains the logic and a

business logic so it contains one or

many SQL statement depending upon what

we are writing in the function body as

you can see on the screen there are if

you need to divide the user defined

functions in some broad category then we

can divide into two broad categories one

is the scalar value functions and one is

the table valued function

the table value function can again be

divided into a line table value

functions and multi-statement table

valued functions let's move to the next

slide let's first discuss about what are

the scalar functions in SQL

scalar functions returns a single data

value of the type defined in the written

Clause if it is a nice scalar function

we even don't need a function body

we use scale functions when multi

statements need to be provided within

beginner and block so let's discuss

about the syntax as I mentioned that the

syntax contains header and body so the

the create alter function which is

basically the header of the functions in

the header we can Define the parameters

the return type parameter and then in


the beginning and end we Define the

function body what are the SQL statement

or any competitions or calculation which

we are doing you basically do it in the

body of the function

so if we need to summarize the scalar

functions are functions which retains a

single value they return scalar values

of single values that can be used

anywhere a constant expression can be

used and every function whether it is a

scalar or or whether it is like table

value functions every function must

return a result using the return

statement this is kind of mandatory so

let's see some examples of the scalar

functions

so in this example we are creating a

function with the name FN underscore get

department number so we are creating a

parameter employee ID of the data type

in here this functions basically returns

a int data type

then there is a begin keyword after

begin keyword we are defining the body

the body we are writing select

department number from employee where

employee ID is employee ID where at the

rate employed is the parameter which


will pass when will execute this

function or we'll run this function so

in the right hand side we are executing

this functions and we are executing

these functions in the where Clause just

pay attention so the where Clause we are

mentioning where department number

equals to and then we are calling the

function by providing the parameter so

when this function will execute it will

be replaced by the value which the

function will return and then that value

will be used in the where Clause to

filter the data so let's discuss some

examples of functions for better clarity

let me open management Studio

let me close these queries first

so we'll first create a function a

scalar function without any parameters

so this is the name of the function now

parameters

we are not creating any parameters here

the written type is end and I'm just

returning in the return statement we

have just provided a SQL statement that

selects some salary from employee after

executing this function will be created

this is a scalar function so if you want

to verify whether the function has been

created successfully then we have to


refresh our database so we have created

this function in employee DB database

I'll refresh that and I'll expand the

programmability in programmability node

we have sub node called functions again

in functions we have four nodes table

value functions scalar value functions

aggregate functions and system functions

if I'll expand the scale value functions

we can see the name of the functions

here

so in order to execute this function we

have to write select statement followed

by the name of the function

and try execute we have provided the

parenthesis

so this function will return the sum of

the salary from employee table so let me

show you the data which is there in the

employee table so that we can verify our

result whether we I get the right result

or not

so if you calculate this we'll get 570 K

this is the sum of the salary for all

the employers since we have salary for

the three employees only

so this is how we'll create the

functions without any parameter let's

see how we can create functions with


parameter

so in this function

we are providing two parameters first

name and the data type of the parameter

is vacant 50. the second parameter is

the last name and the data type of

second parameters again with the same

length as of the first parameter written

type is also of the same data type and

then in the body we are executing the

SQL statement so what we are doing we

are just concanating so if it is a

mathematical operations if you provide

the plus operator then we'll add the two

values but if it is string or where care

then it will connect the string space is

a function and it is an inbuilt function

in SQL which basically add a space empty

space so what we are doing we are con

connecting first name and last name and

we are adding a space between the two

names to make it more readable so as you

can see when I hovering over the space a

keyword it is giving me a message that

this is a built-in function so let me

create this function first function has

been created

again this is a slip function but with

parameters Let me refresh the scalar

valid function node and I can see the


function name let me execute this

function

name of the function and then we have to

pass the parameters so I pass two

parameters here

comma and the name of the second

parameter

why I'm enclosing it in single code

because

this is a string type

and if you want to add in areas for the

column name

we can mention it as

full name

so if I'll execute it again you'll get

the reason U root here

so this is how we'll create a functions

with multiple parameters

and we can call the functions in the

select statement or we can sorry when we

call in the self statement right and we

can even call the functions in where

Clause as we saw in the example in the

PPT again in the previous example

let me first increase the font size we

can even use the functions in the where

Clause so how we can use it let's assume

I'm calling this query select star from

employee and let me first alter this


function so to alter this function we

have to use the alter keyword and

instead of sum I am just finding the

average salary of the employee then I'm

executing again so this is how we modify

the function existing function same way

we can modify the store processor also

so alter is the keyword which helps us

to modify the existing functions as well

as existing stored processor

if I have to use the functions in the

backlash so this is how we'll do let me

show you so I'm writing a query so what

I want to do is that I want to select

the employees whose salary is greater

than the average salary

so I'll write where Clause where

salary is greater than then I'll call

the function

so if I execute it now

I'll get only one result because there's

only one record of one employee whose

salary is greater than the average

salary of all the employee so this is

how we can include or we can call the

function in where Clause as well as in

the select statement as per our business

requirement

so let's move to the next topic

so we are clear with the scalar


functions I believe

so let's move to the next type of

function that is the table valid

functions and as I mentioned earlier we

have two types of our table valued

function one is n line one is

multi-valued so inline table value

functions are a subset of user defined

function that returns a table

so scalar functions returns only single

value whereas the inline table value

functions Returns the entire table

so a line functions if you remember we

have created view in a first module so

we can use inline functions if you want

to achieve the functionality of

parameterized view a line table value

function can also be used to support

parameters in search condition specified

in the where clause

so these are the some of the rules uh

which are common for the inline stable

valid functions the written class

contains only the keyword table format

need not to be defined for the return

value there is no function Body

delimited by begin and and end the

return Clause contains a single select

statement in parenthesis and the table


valid function accepts only constants or

the local variable arguments

this is the Syntax for the inline table

value functions as you can see on the

slide so the return type is stable here

and we generally have the SQL statement

so this is an example

the last slide we saw the syntax this is

the example

so here in

this example we are creating a function

get employee info we are passing the

parameter employee ID and it is

returning the values as a table not as a

single value

and the return statement we are

providing the select statement where we

are returning the values of employee

table and we are filtering the result

sense by using the parameter employee ID

and this is how we'll execute so if you

remember when we uh

executed the scalar value function

please don't use select star from we

simply mentioned select and the name of

the function but if we are using table

value function then we are using the

select star from because we we are kind

of as you mentioned we kind of use it

for parameterized view so if you need to


fetch the values from views then again

we use select star from the name of The

View

so let's see uh an example of inline

table value function

let me open management Studio

so this is example of inline functions

with node parameter we can create

parameter in the same way we created the

parameter uh where we Define the

parameters for the scalar value

functions so I'm creating a function top

10 customers we are returning a table

and in the return statement I am just

writing a select statement select top 10

from employee let me execute this to

create this function now execute this

function so to execute this I have to

mention the select Clause select star

from and then the name of the function

so I am getting so there are only nine

rows so it's just fetching the nine only

so if I can go ahead and modify it

instead of top 10 let me modify it to

top fine so to modify the function we

have to use the alter keyword

so we've got the top five results this

is how we create the inline table valid

function
so this is example of the functions

without any parameters if you required

we can go ahead and create a parameter

as well so to create the parameter we

have to define the parameter name here

and then we can uh we have to provide

the name of sorry data type of a

parameter

and then we can write a where clause

now let's say where employee ID is

create an employee ID command executed

successfully and now if I to run this

I'll pass a value to the function if

I'll execute it will get the values

in the result set

whose employee ID is greater than 1 0 0

3. I hope this is clear and let's move

to the next topic

so we'll discuss the next category of

table valued function that is the

multi-statement so in the inline

function we can use a single statement

but in multi statement table valid

function we can use multiple statements

so again they also written a table data

type

so the written Clause defines the format

of the table we cannot provide the

format in the Align table value function

but yes we can provide the format of the


table in multi-statement table valid

function the transact SQL statement in

the function body build and insert rows

into the written variable defined by the

written clause

and the rose inserted into the variable

are written as the tabular output of the

function so here we have the Syntax for

this to modify we use alter keywords to

create we use create keywords name of

the function if you wish we can Define

the parameters which you can consume in

the function body written type will

always be the table but here we can

Define the format which is not available

in the inline table valid function let's

see an example so this is an example

here so we are defining the format of

the table in we are defining like that

this the table will be the get

employee info and we are providing four

columns here and we are defining the

data type we are defining the constant

on the table we are defining or whether

there is a null constant or not on those

columns and in the function body we are

inserting records in the table and will

fetching from the employee and we are

filtering the result set by using the


parameter which will pass by then we'll

execute the function so let's see one

more example other than this so you can

use the same example and execute it

we'll try it to write the entire thing

then it will take time so I'm skipping

the example in management Studio but the

basic difference between the these two

functions table will function is that

here we can format the table and we can

use multiple statement in the function

body which is not the options in the

inline functions

so we already discussed the benefits of

user defined functions modular

programming it saves time because uh we

can write or dump the statements in a

function and use it or call it as many

as number of times its cost executions

because of his it caches the execution

plan and use it for the subsequent calls

and it reduce the network traffic so

these are few of the main benefits of

user defined functions

[Music]

now let's come to our topic that is SQL

versus MySQL so as the first topic of

comparison we have the definition so

what is the definition of SQL SQL is the

standard language for operating managing


and accessing databases now let's see

what is the definition of MySQL so MySQL

is a relational database management

system for storing retrieving modifying

and administering databases so next

point is history so for SQL SQL was born

in 1970 as a programming language known

as SQL it was developed by Microsoft

Corporation but now it is also known as

SQL while MySQL claims to be the first

open source relational database in the

early 1990s it was developed by MySQL a

b and is currently owned by Oracle

Corporation now looking into the

complexities to use SQL efficiently you

must first learn and then grasp the

language to start working with SQL while

for MySQL you can easily access it by

downloading and installing the same now

coming to the usage SQL is a programming

language so it can be used by querying

and operating while MySQL allows for

data manipulation storage modification

and deletion in a tabular format now the

syntax or format so SQL is a programming

language as we all know now the syntax

and format are fixed it's declarative

and easy to use it starts with the

clause and ends with a semicolon while


MySQL is a software and it is not a

programming language hence it does not

have any commands or any format now the

updates since SQL is a programming

language it is fixed and command remains

unchanged and we can't update it while

MySQL has its latest updates and

versions for enhanced performance now

for supporting language SQL was designed

for Windows but it also works on Linux

Mac OS in its most recent versions while

MySQL is a cross-platform compatible

running on Linux Mac OS and windows as

well now coming to the data security

SQL servers are secured as no third

party or Outsiders are allowed to

manipulate data while in MySQL it is

susceptible to more security threats due

to its open source nature it gives

access to data manipulation and

modification to unauthorized users as

well during the runtime

foreign

ly known as not only SQL database

provides a mechanism for storage and

retrieval of data and is the next

Generation database this kind of

database has no specific schema and does

not have tables with rows and columns

storing data values but can definitely


handle large amount of data so if you

consider the example on the screen we

have an employee database which has two

collections that is the employee and the

projects collection now each of these

collections have documents which are

basically the data values so if you just

want to understand these terms then you

can just consider the collections to be

your tables and the documents to be your

fields in the tables so if you compare a

SQL database and a nosql database for

example let's just say we have an

employee database where you know there's

an employee table with around 10 columns

right that is basically the 10 Fields

now in the nosql database what will

happen is the employee table itself will

be taken as a collection and each of

these fields will be did as documents

now the most interesting part of nosql

is that these kind of databases do not

have to use the same schema for the

presence of multiple documents in one

collection so since nosql has Dynamic

schema that means that you know multiple

documents can be present in a single

collection and also each collection can

have different documents so you can have


a document in the collection which has

both employee ID and employee name and

also you can have a document in the same

collection which do not have the ID and

just toast the name so that's how guys

you can play around with Collections and

documents in nosql database apart from

this let me just also tell you that you

know there is no specific query language

present in nosql so basically the

language that you use to retrieve data

is completely infrastructure based that

is basically how you store your data and

where you store your data lastly there

are no or very few relationships present

in a nosql database as you do not have a

predefined schema but you do have a

dynamic schema in which we can put all

the required information in a collection

right when you have a dynamic schema and

you have the option of putting all the

required information in a single

collection and the collection can differ

in the same schema itself you actually

do not need any relationships to be

present right so that's how guys a nosql

does not have or has very few

relationships so guys if I just have to

summarize nosql for you then nosql is a

type of database which do not have a


predefined schema a query language and

has no tables it follows a method of

storing data in a dynamic schema with

less or no relationships and can handle

humongous amount of data let's now see

how these databases stand against each

other so in this Face-Off we'll be

comparing both these databases based on

the grounds such as the type of database

schema database categories complex

queries hierarchical data storage

scalability Language online processing

based properties and external support

let's get into the detail with the first

comparison factor that is type of

database now when we compare these

databases based on this Factor let me

just tell you that you know SQL is

essentially called a relational database

and it organizes structured data fields

into defined columns so database can

have n number of tables and each table

can have M number of columns with the

data stored in it each table can be

related to the other tables also right

so if you have around 10 tables then

those 10 tables can have around two to

three columns so you can say more than

that columns in each table and all these


10 tables can be related to each other

coming to nosql no SQL is a

non-relational database which provides a

mechanism for storage and retrieval of

data in the nosql database data is

modeled in the form of Collections and

hence it tries to avoid relations as I

just explained you before so guys if you

have to compare these databases based on

this Factor then SQL is essentially a

relational database and nosql is a

non-relational database or a distributed

database next we'll be comparing these

databases based on the schema while

comparing these databases based on this

Factor let me tell you that SQL needs a

predefined schema for structured data so

before you start using SQL to extract

and manipulate data you need to make

sure that you know your data is

predefined in the form of tables coming

to nosql well nosql databases have a

dynamic schema for unstructured data so

if you're using the nosql database then

there's no predefined schema present and

the complete schema of your data

completely depends on how you wish to

store the data that is which fields that

is basically Which documents that you

wish to store in which Collections and


how you wish to store them so guys that

was about schema the SQL has a

predefined schema and the nosql has a

dynamic schema now moving on to the next

parameter which is database categories

now SQL databases are basically the

table based databases so as I explained

in the previous factors the SQL

databases can have n number of tables

related to each other and each table can

have M number of rows in column storing

data in each cell of the data now

similarly if we talk about the nosql

databases the nosql databases have

mainly four categories of databases that

is document database the key value

stores to craft stores and the white

column stores coming to the document

database now this kind of database pairs

each key with a complex data structure

known as a document it can contain many

different key value pairs or the key

error pairs or even the nested documents

coming to the key value stores these are

the simplest form of nosql database so

every single item in the database is

stored as an attribute name or a key

together with its value now coming to

the craft stores the craft stores are


basically used to store the information

about networks such as the social

connections now the craft stores mainly

include the neo4j and the hypograph DB

coming to the last kind of database

category of nosql that is the white

column stores the white column stores

such as as Cassandra and HBS are

optimized for queries over large data

sets and stores Columns of data together

instead of rows so Guys these were

mainly the four categories of nosql

database that is the document database

the key value stores the craft stores

and the white column stores now this

might have given you an idea of you know

the SQL databases basically represent

data in the form of tables which consist

of n rows of data whereas the nosql

databases are the collection of key

value pairs documents graph databases or

white column stores which do not have a

standard schema definitions which it

needs to stick to so guys this was the

main difference between SQL and nosql

that SQL is basically the table based

databases with a predefined schema and

the nosql databases mainly have

different categories of databases with a

dynamic schema so I hope I'm clear with


this file next let's discuss how these

databases fit for complex queries now

when we talk about complex queries let

me just tell you that you know SQL is a

good fit for complex query environment

as the schema and C databases is

structured and has proper tables so even

if you wish to apply nested queries with

many sub queries inside the outer query

you can easily do by using the proper

table and column names and you can

retrieve the required data coming to the

nosql databases the nosql databases are

not a good fit for complex queries as

they don't have standard interfaces to

perform complex queries and the queries

themselves in nosql are not as powerful

as the SQL query language so this is

basically because you know they're not

written in a specific language and the

language in which they are written is

completely based on the database

infrastructure you can see the schema so

if you have to compare how these

databases fit for complex queries then

let me tell you that SQL is a better fit

for complex queries when compared to

nosql now moving on to the next factor

of comparison that is hierarchical data


storage now when we compare the

databases based on this factor that will

tell you that the SQL databases are not

best fit for hierarchical data storage

now this is because as number of tables

increase the complexity of relating them

to each other also keeps increasing now

in such a scenario you cannot relate

humongous amount of tables with n number

of columns to each other right but

coming to nosql database the nosql

database fits better for hierarchical

data storage as it follows the key value

pair way of storing data similar to the

Json data now nosql databases are also

highly preferred for last data sets when

compared to the SQL database and one

such example is hbase so basically

edgebase is used for this purpose next

point of comparison will be scalability

now SQL databases are vertically

scalable you can load balance this

database by optimizing your Hardware

requirements such as increasing the CPU

Ram SSD Etc on a single server on the

other hand the nosql databases are

horizontally scalable you can do load

balancing by adding more servers to your

cluster so that with the help of these

servers you can handle large traffic so


on the note of scalability SQL is

vertically scalable and nosql is

horizontally scalable next we'll be

comparing these databases based on

language the SQL databases have a

specific language and it does not vary

from database to database so basically

the SQL databases use the structured

query language for defining and

manipulating the data which is very

powerful coming to nosql the nosql has

no specific language and it varies from

database to database in the nosql

databases the queries are focused on the

collection of documents and sometimes

the language used in nosql is also

called unstructured query language so on

the note of language guys the SQL uses a

proper defined language that is the

structured query language and nosql has

no specific language and the language

differs from database to database now

moving on to the next parameter which is

online processing now when we compare

both these databases based on online

processing SQL databases are the best

fit for heavy duty transaction type

applications as its most stable and

Promises the atomicity as well as the


Integrity of data while you can

definitely use nosql for transaction

purpose yet it is still not compatible

and stable enough and high load for

complex transactional applications so

you can understand by this that you know

SQL is mainly used for oltp that is

basically online transactional

processing and nosql is mainly used for

of AP which is online analytical

processing so if I have to just explain

these terms oltp and olap for you then

oltp is basically characterized by large

number of short online transactions such

as insert update and delete the main

emphasis for oltp systems is to put on a

very fast query processing maintained

data Integrity in multi-access

environments and an Effectiveness

measured by number of transactions per

second in oltp databases there's proper

detail and current data and the schema

used to store transaction database is in

the entity model you usually 3nf now

coming to olap that is basically online

analytical processing this is basically

characterized by relatively low volume

of transactions and queries are often

very complex and involve aggregation for

olap systems response time is an


Effectiveness measure and olap

applications are widely used by data

mining techniques so in the olap

database there is aggregated historical

data stored in multi-damage to schemas

usually the star schema so guys that was

about oltp and olap so you can just

understand this point that you know SQL

is mainly used for heavy transactional

type applications and nosql is basically

used for analytical processing and can

definitely be used for transaction type

applications but yet it is still not

stable for high load applications so now

the next point of comparison we have is

base properties now SQL databases

emphasize on the asset properties that

is the atomicity consistency isolation

and durability whereas the nose SQL

database follows the cap theorem that is

the consistency availability and

partition tolerance so let's talk about

both of them one by one starting with

the asset properties asset properties

mainly stand for atomicity consistency

isolation and durability now atomicity

basically refers to the transactions

that are completely done or failed where

the transaction refers to a single


logical operation of data now this

basically means that you know even if

one part of the transaction fails the

entire transaction fails and the

database state is left unchanged coming

to consistency the consistency ensures

that data must meet all the validation

rules in simple words you can just say

that you know your transaction never

leaves the database without completing

its state coming to isolation the main

goal for isolation is basically the

concurrency control and finally the

durability the durability means that you

know if a transaction has been committed

it will occur whatever may come in

between such as the power loss crash or

any sort of error so guys that was about

the asset properties that is basically

the atomicity consistency isolation and

durability coming to the capped here the

cap theorem or the Eric Brewer's theorem

states that you know we can only achieve

at most two out of three guarantees for

a database that is basically the

consistency availability and partition

tolerance so here the consistency means

that you know all the nodes in the

network say the same data at the same

time or the reader gets most recently


written data coming to availability

availability is the guarantee that every

request receives a response about

whether it is successful or failed and

the more number of users A system can

cater to a better is the availability

coming to the partition tolerance the

partition tolerance is a guarantee that

the system continues to operate despite

arbitrary message loss or failure of any

part of the system in other words even

if there is a network outage in the data

center and some of the computers are

unreachable still the system continues

to perform now out of these three

guarantees that is consistency

availability and partition tolerance no

system can provide more than two

guarantees now since in the case of

distributed systems the partition of

network is must the trade-off is always

between consistency and availability so

you can just understand that you know

nosql cannot provide consistency and

high availability together so guys that

was about the base properties SQL is

completely based on the asset properties

and nosql is based on the cap theorem

finally the last but not the least


factor of comparison is external support

now external support is available for

all SQL database from their vendors

there are also a lot of independent

consultations who can help you with SQL

database for a very large scale

deployment this is mainly due to since

SQL has been into existence since more

than 40 years and people have been using

SQL regularly now coming to nosql for

some nosql databases you still have to

rely on the community support and only

limited outside experts are available

for you to set up and deploy a large

scale nosql deployments this is mainly

because nosql has come into existence

and many of them haven't explored it yet

much so folks with this we come to an

end of this Face-Off between SQL and

nosql I hope all the comparison factors

were clear to you guys now in this

session since we have discussed so much

about SQL and nosql let me just show you

some examples of the scene so as you can

see on my screen these are the examples

for SQL and nosql so the popular

examples for SQL are the Oracle the

postgres sequel the my sequel the

Microsoft SQL server and sqlite now

coming to the examples of nosql then


examples of nosq will have redis mongodb

Apache headspace big data table and

Cassandra now out of the lot the most

popular databases in today's market are

basically the MySQL and mongodp from the

SQL and the nosql sections so next in

this session we'll be comparing MySQL

and mongodb based on various parameters

now before I move on with the comparison

of MySQL and mongodb let's first

understand what is my Sequel and what is

mongodb starting with my sequel my

sequel is an open source relational

database management system that works on

many platforms it provides multi-user

access to support many storage engines

and is backed by Oracle so you can buy a

commercial license version from Oracle

to get premium Support Services now the

features of MySQL as you can see on my

screen so basically MySQL provides

comprehensive application development

scalability and flexibility and its open

source and provides 24 into 7 support

provides High availability high

performance support secures your data

provides robust transaction support

requires low total cost of ownership and

provides ease of management now coming


to comprehensive application development

MySQL has plug-in libraries to embed the

database into any application so it

basically supports stored procedures

triggers functions views and many more

application Development coming to

scalability and flexibility with mySQL

you can run deeply embedded applications

and create data warehouses holding a

humongous amount amount of data next

talking about open source in 24 into 7

support this relational database

management system can be used on any

platform and offers 24 into 7 support

for open source and Enterprise Edition

talking about high availability MySQL

can run high speed Master Slave

replication configurations and it offers

various cluster servers talking about

high performance MySQL provides fast

load utilities with distinct memory

caches and tables index partitioning

next about data protection MySQL

supports powerful mechanisms to ensure

that only authorized users have access

to the databases next talking about

robust transactional support MySQL holds

the asset properties that is basically

the atomicity consistency isolation and

durability properties and allows


distributed multiversion support and

talking about low total cost of

ownership MySQL make sure certain it

reduces the licensing costs and Hardware

expenditures and talking about finally

the ease of management this software can

be easily downloaded and also uses an

event scheduler to schedule the task

automatically so guys the features of

MySQL are basically the comprehensive

application development the scalability

and flexibility open source and 24 7

support High availability high

performance secure data protection

robust transaction support low total

cost of ownership and ease of management

now coming to mongodb mongodb is a

non-delational database which stores

data as documents in a binary

representation called bson that is

basically binary Json this kind of

database stores related information

together for fast query access to the

mongodb query language the features of

mongodb are as you can see on my screen

that is indexing replication add-on

queries schema list and sharding talking

about indexing mongodb indexes are

created in order to improve the search


performance next talking about

replication mongodb distributes the data

across different machines coming to

adopt queries mongodb supports ad hoc

queries by indexing the base on

documents and uses a unique query

language coming to schema list it's very

flexible because its schema list

database and is written in C plus plus

and talking about sharding mongodb uses

sharding to enable deployments with

large data sets and high throughput

operations so Guys these are the mainly

five features of mongodb that is

indexing replication Adobe query schema

list and sharding so guys now that you

know what MySQL is and what mongodb is

let's compare these two databases based

on the grounds that you can see on the

screen that is the query language the

flexibility of schema the relationships

security performance support key

features replication usage and active

community so now let's get into detail

with the first comparison factor that is

the query language now MySQL uses the

structured query language to communicate

with the database not only is it simple

it is also very powerful language which

consists of mainly two parts that is the


data definition language and the data

manipulation language mongodb on the

other hand uses an unstructured query

language to build a query in Json

documents you need to specify a document

with various properties you wish the

results to match it is typically

executed using a very rich set of

operators that are linked with each

other using Json now mongodb treats each

property as having an implicit Boolean

and it basically also supports Boolean

or queries but you must definitely use

the special operator dollar or to

achieve it so to make you understand

better I've considered the example on

the screen so to insert the data into

the employees table in the SQL query you

just have to type in insert into

employees that is basically your table

name and insert into is your SQL syntax

and then you mention the column names

that is the employee ID and employee age

and then you use the SQL syntax that is

the values and mention the values for

the fields so to just insert data into

the table you mentioned insert into

employees employee ID employee age

values and the new mentioned the values


now similarly in the same scenario if

you wish to insert the data into a

collection which is stored in the

mongodb database what you simply have to

do is you have to mention

db.employs.insert where employees is the

collection name and then you have to

mention employee ID and then mention the

value and then mention again age and the

value so basically over here employee ID

and age are basically the fields so guys

this is how you know the query language

between MySQL and mongodbit efforts next

we'll be comparing these databases based

on the flexibility of schema now in the

perspective of flexibility of schema let

me tell you that you know before you can

store anything in MySQL you need to

clearly Define tables and columns and

every Row in the table should have the

same column now this is basically

because there isn't much space for

flexibility in the manner of storing

data if you follow normalization for

example if you have an employee database

you need to create a table which can

hold the date of employees now this

table can have many attribute values

such as the employee ID employee name

and so on now similarly talking about


mongodb one of the best things about

mongodb is that you know there are no

restrictions on the schema design so you

can directly drop a couple of documents

within a collection and it isn't

necessary to have any relations between

those documents now the only restriction

with mongodb is that you need to

frequently optimize your schema based on

how the application will be accessing

the data now mongodb stores the data in

the Json type manner so if we consider

the previous example that is the

employee table the data in mongodb would

be stored as you know employee ID and

then we have to mention the employee ID

that is basically the value for employee

ID then employee name and then you have

to mention the employee name employee

age and so on so basically this will be

considered as a document and now these

documents can be stored in a collection

as well so basically mongodb creates

schema list documents which can store

any information you want though it may

cause problems with the data consistency

whereas the MySQL follows a strict

schema template now moving on to the

next parameter which is relationships


now when we talk about relationships

MySQL supports the join operations so to

explain you in simple terms join makes

the relational database relational so

basically the join allows the user to

link the data from two or more tables in

a single query with the help of the

select command so for example if you

want to retrieve the data from the

employee in the projects table based on

the matching column you can easily

obtain the desired data by applying any

type of join such as the inner left

right or full based on your need now

coming to mongodb well mongodb does not

support the join statements but it

supports the multi-dimensional data

types such as arrays and even other

documents so the placement of one

document inside another document is

basically known as the embedding of

documents and mongodb supports the

embedding of documents so talking about

relationships guys MySQL supports the

join statements and the mongodb does not

support any joint statements next let's

discuss the security factor for both of

them now talking about MySQL first MySQL

uses a privilege HB security model the

space that unit basically authenticates


a user and facilitates it with the user

privileges on a particular database such

as create select insert update and so on

now coming to mongodb mongodb uses a

role-based access control with a

flexible set of privileges its security

features basically include the

authentication auditing and

authorization not only this but it is

also possible to use the transport layer

security and the secure socket layer for

encryption purposes in mongodb so

basically this ensures that unit is only

accessible and read it by intended

client no other client can go through

the documents so guys that's how the

security is provided in MySQL and

mongodb now let's move over to the next

factor of comparison that is performance

so on comparing MySQL and mongodb on

this parameter MySQL is quite slower in

comparison to mongodb when it comes to

dealing with the large databases this is

mainly because you know MySQL can't cope

up with large and unstructured amounts

of data whereas DB can so that's the

reason guys mongodb is much faster than

MySQL now talk about Bongo TV mongodb

has the ability to handle large


unstructured data it's much faster than

MySQL because it allows the users to

query in a different manner that is more

sensitive to workload but yes there is

as such no Benchmark on you know which

database is faster because you know only

it demands your data and your

infrastructure can tell what you need

and which database can provide you the

output faster so guys that was about

performance next we'll be comparing

these databases based on support well

both of them offer excellent support 24

7 for security fixes maintenance

releases bug fixes patches and updates

so there is assets no difference between

both of them based on this parameter as

both of them offer good support So guys

that was about support now moving on to

the next parameter which is key features

the key features of MySQL in mongodb are

as you can see on my screen let's start

with my sequel first the key features of

MySQL are mainly triggers an SSS support

provides Tech searching and indexing

also allows query caching provides

integrated replication support and also

provides different storage engines so

Guys these were the key features of

MySQL not talking about mongodb mongodb


supports Auto sharding comprehensive

secondary indexes in memory speed native

application and embedded data model

support so these were few features of

MySQL and mongodb so yes there are

various differences between both these

databases but there are few key features

you know which help both MySQL and

mongodb to win in their own Market now

next point of comparison we have is

replication now MySQL supports the

master sleeve replication and the master

master application as of MySQL 5.7.6 and

later and this kind of multi-source

replication allows you to replicate from

several Masters in parallel talking

about mongodb mongodb supports the

built-in replication sharding and auto

elections so by using autoelections you

can set up a secondary database to

automatically take over if the primary

database fails so sharding allows for

horizontal scaling which is difficult to

implement in MySQL as MySQL is

vertically scalable not only this but

mongodb also uses replica sets to create

multiple copies of data so each member

of the replica set can have the role of

primary or secondary at any point in the


process and the read and writes are done

on the primary replica by default and

then replicated to the secondary

replicas so guys this was about the

replication MySQL supports the Master

Slave replication and the mongodb

supports built-in replication chart

adding and auto elections next we'll be

comparing these tools based on Usage Now

for this Factor I'm going to tell you

where you can use MySQL and mongodb so

let's start with mySQL first MySQL is

the best fit for data with tables and

rows this works better for small data

sets and allows frequent updates MySQL

is also used for strong dependency on

Multi row transactions and is also used

when you want to modify large volumes of

Records talking about mongodb mongodb

best fits for unstructured data and

works better for large data sets this is

also used when you have high write loads

and high availability in unstable

environment and the data is completely

location based so this was about MySQL

and mongodb guys MySQL mainly best fits

for data with tables and rows and

mongodb best fits for unstructured data

finally the last but not the least

factor of comparison is the active


Community the mySQL database is mainly

owned and maintained by the Oracle

corporations so they offer a developer's

Zone on the myc equal website and the

community for MySQL is I would say much

better than that of mongodb so if you

want to support both of them offer good

support but yes if you talk about active

Community then MySQL has a better active

Community than compared to mongodb so

guys now that I've told you so much

about MySQL in mongodb let me just shift

to my MySQL workbench and mongodb

Compass so that I show you how you can

create tables and databases in MySQL and

how you can create databases and

collections in mongodb so first we'll be

looking into my sequel so for that I'll

open my MySQL workbench so as you can

see on my screen this is my MySQL

workbench so I'm just going to open my

connection

so guys this is how your MySQL workbench

looks now to show you how you can use

MySQL I've already written the command

so I'm just going to tell you how you

can use them so to create a database

I've used a query create database and

I've mentioned the database name that is


employee info so this is a SQL language

guys where you know create and database

are the SQL syntax and employ info is

the data parameter so I'm going to just

execute this particular query now once

the query is executed you can clearly

see that you know the database has been

created now to use this database you can

just directly use database name that is

employee info so if I just execute this

query again you'll clearly see that you

know we'll be using this particular

database Now to create a table inside

this particular database you can use the

query like you know create table table

name and then you mentioned all the

field names and the data types right so

over here I have different field names

like the employee ID employee first name

last name age email ID phone number and

address and their specific data types

right so I'm going to just execute this

particular query

so once I execute this particular query

you can see that you know a table has

been created so now if we just look into

our databases we have a database that is

employee info and then we have a table

inside it now to insert data into the

table what you can use is you can just


use the query insert into table name

that is employee over here mention all

the field names then use the SQL syntax

keyword values and then mention all the

values right so here I've written a

query as insert into employee employee

ID first name last name age email ID

phone number address values and then

I've mentioned the values right so I'm

going to just execute this particular

query so once the query has been

executed you can clearly see that you

know data has been inserted into the

table so I'll just go to the employee

input table coder tables option go to

employ and then I'm going to just look

into the table so when I just check into

the option of view you can clearly see

that you know our first record has been

inserted so guys that's how it's really

simple to use MySQL and with the help of

my SQL workbench you get the GUI

experience you know where you can easily

mention your required query studies and

then get the outputs right so that was

about my SQL workbench guys now shifting

to do you become pass so guys this

is how the mongodb compass looks so

basically I've already created a


database now if you just wish to go and

check how a database has been created

what you can simply do is you can go

over here to my cluster and once you go

to my cluster you get an option of

create database right so I'm just going

to create a database so let's say I

mention it to be employee info and then

over here since I've told you database

has Collections and then collections

have documents so basically a group of

documents is Collections and a group of

collections is a database I'm going to

mention my first collection name let's

say you know employee and then I'm gonna

just click on create database so once I

click on create database you can clearly

see that you know my database has been

created that is employee info so I'll

click on this and you'll see that you

know we already have a predefined

collections created now apart from this

you can also have a number of

collections to be created but since I'm

just showing you how you can use mongodb

I'm not going to create many more

collections this is just a single

collection that I've already created now

what you can do is you can again create

documents inside this particular


collection to do that you have to click

on this collection that is the employee

collection and over here you get an

option for insert document right so you

can just click on this option of insert

document mention the required values

that is basically the idea dot object ID

so basically over here you can just

mention employee ID and in this section

you can just mention the employee ID now

similarly you can mention the employee

name also and over here I'll mention the

employee name to be let's say sahity

right now over here if you see we can

also use the data type so let's just say

you know our employee ID should be int

so I'll just mention it to be end and

employee name to be string right so

that's how you can mention the data

types for your documents and then once

you've inserted all the required values

you can just click on insert

so once you click on insert you can

clearly see that you know your document

has been created now this you can either

view in the form of a table that is

basically you know which document ID

basically has which employee ID that is

which data type and also the employee


name or you can also view it as a list

so I was previously viewing it as a list

this is how you can create a database

and then create a collection and

documents well I'm not going to go in

depth of how you can use this mongodb

compass and how you can explore much

more features of this so guys it was

just a short demo on you know how you

can use MySQL workbench and mongodb

Compass to handle structured data and

unstructured data so folks with this we

come to an end of the space off between

MySQL and mongodb and I hope you

understood all the points now knowing so

much about MySQL and mongodb would have

definitely raised a question on your

mind whether to use mongodb or MySQL for

your businesses so guys well there is no

clear winner between both of them the

choice of database completely depends

upon the scheme of your database and how

you wish to access is it nevertheless

you can use MySQL when you have a fixed

schema High transaction low maintenance

data security with a limited budget and

mongodb while you have an unstable

schema no specific database

administrator High availability cloud

computing involved with inbuilt sharding


so guys this is when you use MySQL in

mongodb there's no clear between both of

them it completely depends on you which

type of database you would want to go

for for your businesses and how you

think your business will be benefited by

choosing which database so there won't

be any final verdict as to which among

them is best as each one of these Excel

based on your requirements

foreign

statement

so I'll start by explaining you what is

the delete command well the delete

command is basically used to delete a

row in the table so you can also roll

back data after using the delete

statement and it is a data manipulation

command coming to the truncate statement

the trunk it statement is basically used

to delete all the rows from a table and

you cannot roll back the data this is a

data definition language command and it

is faster than the delete command so if

anyone asks you the difference between

the delete and the truncate statements

don't forget to mention that you know

the trunket statement is definitely

faster than the delete statement and the


truncate statement is from the data

definition family and the delete

statement is from the data manipulation

family right now moving on to our next

question that is what are the different

subsets of SQL well the different

subsets of SQL are mainly the data

definition language the data

manipulation language the data control

language and the transaction control

language now coming to the data

definition language this set of language

consists of the commands that can be

used to define the the database schema

so whenever you want to define the

database schema you can use the commands

from this particular language coming to

the data manipulation language the

manipulation language consists of all

the commands that deal with the

manipulation of data present in the

database so for example if you have n

number of tables and you want to

manipulate the data in present in those

tables then you use data manipulation

commands coming to the data control

language the data control language

includes the commands which deal with

the right permissions and other controls

of the database systems so for example


you work for an Enterprise and the

Enterprise has a database now obviously

all the employees will not have the

access to the database right so data

control language mainly deals with how

you give the user permissions to access

to the database now coming to the last

type of language that is the transaction

control language this basically includes

the commands which mainly deal with the

transaction of the database whenever you

want to roll back or you want to perform

any various kind of transactions then

you use the set of commands from this

language right so I hope I'm clear so as

I said there are many only four

different subsets of SQL that you should

mention that is the data definition

language the data manipulation language

the data control language and the

transaction control language now moving

on to our next question that is what do

you mean by database Management systems

and what are the different types of it

so now if I have to define the database

management system for you then a

database management system is a software

application that interacts with the

users applications and the database


itself to capture and analyze the data

so the data stored in a database can be

modified retrieved and deleted and can

be of any type like the Springs numbers

images

Etc so you can basically store any kind

of data now the different kinds of

database Management systems are the

hierarchicals the relational the network

and the object oriented database

Management Systems now talking about the

hierarchical database Management Systems

this type of database management system

has a style of predecessor and the

successive type of relationship so it

has a structure similar to data for tree

wherein the nodes represent the records

and the branches of the three represent

the fields coming to the relational

database management system this type of

database management system uses a

structure that allows the user to

identify and access data in relation to

other the piece of data in the database

the network database management system

supports many to many relations wherein

multiple member records can be linked

and the object-oriented database

Management Systems use a small

individual software called objects and


each object contains a piece of data and

the instructions for the actions to be

done with the data so I hope I'm clear

with this point so now moving on to our

next question that is what do you mean

by a table and a field in SQL so now the

answer to this question is quite simple

a table basically refers to a collection

of data in an organized manner in forms

of rows and columns and the field refers

to the number of columns in the table if

you have to explain anybody what table

and field mean so basically in SQL you

have a database and a database consists

of n number of tables right so that is

basically a table and the tables have

few column names right so the column

names are basically the fields so you

can explain with an example as you can

see in the screen so over here I have an

employee information table into which

the employee information table is a

table and the column names in the this

particular table are the fields now

moving on to our next question that is

what are joints in SQL now this is one

of the most popular questions that is

generally asked in your interviews so

basically a joint Clause is used to


define to combine rows from two or more

tables based on related columns between

them it is used to merge two tables or

retrieve data from there and there are

mainly four types of joints in SQL that

is the inner joint the full joint the

left join and the right joint right now

moving on to a next question that is

what is the difference between Cad and

where cat2 data type in SQL now this is

one of the most confusing questions that

is generally asked in your interviews

you since you know generally people get

confused between what is care and what

is Firecat data type now both care and

Barca 2 are used for character data type

but wirecat 2 is used for character

strings of variable length whereas the

cat is used for strings of fixed length

so whenever you have strings of fixed

length then you use the cad data types

and whenever you have strings of

variable length then you can use the

wirecat 2 data type now for example Cat

10 can only store 10 characters and will

not be able to store a string of any

other length whereas the varca 210 can

store any length that is either 6 to 8

it completely depends on the variable

right now moving on to our next question


that is what is the primary key now when

you're working in a database field

obviously a company you can have n

number of databases having n number of

tables inside this now each and every

table in a database has to be connected

with the other table right now for that

we need to uniquely identify a table or

you know you can say you need to

uniquely identify a column so basically

primary key is a set of attributes that

can be used to uniquely identify every

Tuple so if there are around three to

four candidate Keys present in a

relationship then out of those one can

be chosen as the primary key now as you

can see on the screen we have an

employee information table which has

columns like you know employee number

employee name employee country and the

employee age now obviously you can

uniquely identify each and every

employee with the employee ID right so

basically that will be a primary key so

over here employee number will be a

primary key now let's move on to our

next question that is what are

constraints so constraints are basically

used to specify the limit of the data


type of the table right so whenever

you're creating a table then you can use

the constraints to set a limit of the

data type of the table it can be either

specified while either creating the

table or you know while you're altering

the table statement so it can be

basically specified in both the ways now

there are mainly five constraints that

you need to understand about that is the

not null constraint the unique constant

the check constant the default

constraint and the index constraint now

the notional constant basically ensures

that a null value cannot be stored in a

column so whenever you mention this

particular constant into a column of

your table then this particular

constraint will make sure that you know

no null value can be stored for that

particular column in the table moving on

to the next constant that is the unique

constant this constant makes sure that

you know all the values in the column

are basically different so if you need

to make sure that you know in a column

you have unique values for each and

every row then you can use this

particular constraint now moving on to

the next constant that is the check


constraint the check constant basically

ensures that all the values in the

column satisfy a specific condition so

if you have a condition you need to make

sure that you know only the values which

satisfy the condition are stored in the

column then you can use this particular

constraint now talking about the default

constraint the default constraint

consists of a set of default values for

a column when no values specified so for

example in a table of 10 rows you know

you have a column in which you do not

specify all the values for all the 10

rows then you can make sure that you

know you will set the default value and

the default value will be automatically

stored whenever you don't mention a

value in that call now moving on to the

last type of constraint that is the

index constraint the index constant is

used to create and retrieve data from

the databases very quickly so I hope I'm

clear with the different types of

constraints that you need to answer

about when you're asked this question

about what are the constraints that you

know now let's move on to the next

question that is what is the difference


between SQL and MySQL now this is one of

the most popular question is generally

us you know because since people

generally get confused between what is

SQL and what is my sequel so let me just

explain you the simple difference

between both of them so SQL is basically

a standard language which stands for

structured query language based on the

English language whereas the MySQL is a

database management system so SQL is

basically the core of relational

database which is used for accessing and

managing the database whereas MySQL is a

relational database management system

which works on many platforms so

basically this provides multi-user

access to support many storage engines

and is backed by Oracle so that's the

basic difference between SQL and MySQL

guys SQL is basically the core of

relational database which is used for

accessing and managing your database and

MySQL is an open source relational

database management system now let's

move forward to our next question that

is what is a unique key now unique key

basically identifies a single row in a

table this basically allows multiple

values per table and also the null


values are allowed so you'll have to

make sure that you know whenever you're

using the unique key you need to have an

idea that you know it identifies a

single Row in the table multiple values

are allowed for the table and also null

values are allowed but yes duplicate

values are not allowed all right now

moving forward to a next question that

is what is a foreign key a foreign key

basically maintains referential

Integrity by enforcing a link between

the data in two tables the foreign key

in the child table references the

primary key in the parent table and the

Forum key constraint prevents actions

that would destroy the links between the

child and the period table so if you

have a database and you know if you have

around 10 tables in that particular

database and then if you want to

maintain relations between all these

tables in the database then you need to

use the primary key foreign key concept

so that you identify the relation

between both these tables with the help

of foreign key now moving forward to a

next question that is what do you mean

by data Integrity now data Integrity


basically defines the accuracy of the

data as well as the consistency of data

store in the database it also defines

the Integrity constraints to enforce

business rules on the data when it is

entered into an application or a

database so if you have to answer this

question then you can answer by saying

that you know data Integrity basically

defines the accuracy and the consistency

of data now let's move forward to a next

question that is what is the difference

between the clustered and the

non-clustered index in SQL the clustered

index is basically used for the easy

retrieval of the data from the database

and is faster than the non-clustered

index the clustered index Alters the way

records are stored in the database as it

sorts out the rows by column which is

said to be the clustered index and only

one table can have a clustered index

coming to the dawn clustered index the

non-cluster index is also used for the

retrieval of data from the database but

yes it is slower than the clustered

index the non-clustered index does not

alter the way it is stored but yet it

creates a separate object within a table

which points back to the original table


rows after searching and also one table

can have many non-cluster indexes the

main difference between both of them are

both are used for easy retrieval of data

but yes the clustered index is faster

than the non-clustered index and only

one table can have only one cluster in

text but yes a single table can have

many non-clustered indexes apart from

that the third difference between both

of them is also that you know the

cluster index Alters the way it records

are stored in the table and the

non-cluster index does not do that now

let's move forward to our next question

that is write a SQL query to display the

current thing now when you attend the

interviews for a database administrator

let me just tell you that not only the

theoretical questions are asked but yes

you are sometimes asked to write the

queries also so they can give you some

scenario based questions so they can

just ask you few simple queries that you

need to make sure that you know you know

them so that's the reason that this

question could be asked that you know

write a SQL query to display the current

date now in SQL to display the current


date we have a function known as the get

date so basically with the help of this

function you can turn the current date

and time stamp so the syntax of the

function is really simple is just get

date and it applies to SQL Server 2017

16 14 12 2008 R2 2008 and 2005. now if

you just have to give an example to the

interviewer about how to write a query

to display the current date you can just

mention the query like you know select

get date so when you execute this

particular query you would see an output

that you know the current date and time

would be displayed as out right so

that's how you can write a query to

display the current date now moving

forward to the next question that is

what are the different types of joints

so as I mentioned before there are

mainly four types of joints that you

need to talk about that is the energy

and the full joint the left join and the

right join so talking about the inner

joint this joint basically returns those

records which have matching values in

both the tables now consider two tables

table a and table B now when you apply

the inner join on both of these tables

you'll observe that you know the output


would be all those records which have

matching values in both the tables that

is table a and table B let's talking

about the full joint the full joint

basically returns all those records

which either have a matching value in

the left or the right table so whenever

you apply full join on both of these

tables you'll see that you know you'll

get an output of all those records which

either have a match in the left or the

right table now talking about the left

join the left join Returns the records

from the left table and also those

records which satisfy the condition from

the right table so if you have table a

and table B and you apply a left joint

to both of these tables then the output

would be all those records from the left

table and the records from the right

table which satisfy the specified

condition similarly the right join is

just the vice versa the right join

basically returns a recourse from the

right table and also those records would

satisfy the condition from the left

table so whenever you apply the right

show into table a and table B and

consider that you know the table B is


right table you'll get all those records

from the table p and also matching

records from table a which satisfy the

condition so these are the various types

of joints that you need to talk about

guys now moving forward to the next

question that is what do you mean by

denormalization now denormalization

basically refers to a technique which is

used to access the data from higher to

lower forms of database it increases the

performance of the entire infrastructure

as it introduces redundancy into the

table and it also adds the Redundant

data into a table by incorporating

database queries that combine data from

various tables in a single table so if

you have to just explain denormalization

you can just say that you know it is a

technique which is used to access data

from higher to lower forms of database

and it basically adds redundant data

into the table by incorporating database

queries that combine data from various

tables so I hope I am clear with this

file now moving forward to the next

question that is what are the entities

and relationships so let me just explain

you what entities are first so entities

can be anything like in a person place


or a thing in real world about which

data can be stored in a database so

table store data that represent one type

of entity so for example applying

database has a customer tables to store

the customer information the the

customer Table stores this information

as a set of attributes that is basically

the columns within the table for each

and every customer so if you consider

you know a customer table has around

five parameters like customer ID

customer name customer phone number

customer email ID and so on then all

these customer ID customer name customer

phone number are basically the column

names that is the attributes for the

entities and customer information will

be the entity now talking about

relationships relational links between

the entities that have something to do

with each other is basically

relationships so for example the

customer name is related to the customer

account number and the contact

information right now this might be in

the same table or it could be in any

other table also right so if you have

two tables out of which one table has


the customer name and the other table

has all the other information like the

customer ID customer name and so on now

these two tables will be related to each

other with a relationship so that the

customer details could be retrieved now

that particular information is basically

relationships now moving forward to a

next question that is what is an index

in previous questions I talked about the

non-clustered index and the cluster

indexes right but what exactly is index

now index basically refers to a

performance tuning method of allowing

faster retrieval of records from the

table so as I mentioned before in the

cluster in the non-clustered indexes

question both of the indexes are

basically used for easy retrieval of

data right so that's what index does

this is basically a performance tuning

method to allow faster retrieval of data

from the table and also an index creates

an entry for each value so to allow the

faster retrieval of records from the

table it basically creates an entry for

each and every value now let's move

forward to the different types of

indexes so well I've already explained

you about two types of indexes that is


the clustered and the non-clustered

index but yes let's understand again

about both of them and also an

additional index that is the unique

index so mainly there are three types of

indexes that is used that is the unique

index the clustered index and the

non-clustered index the unique index

basically does not allow the field to

have duplicate values if the column is

unique indexed so if a primary key is

defined a unique index can be applied

automatically so unique index is mainly

used when you do not want any duplicate

values to be present in the column now

moving to the clustered index the

clustered index basically reorders the

physical order of the table and searches

based on the basis of key values so each

table can have only one clustered index

coming to the third type of index that

is the non-clustered index the

non-clustered index does not alter the

physical order of the table and

maintains a logical order of the data so

each table can have many non-cluster

indexes right so basically guys there

are three types of indexes that you need

to explain about that is the unique the


cluster and the non-clustered index now

moving forward to a next question that

is what is normalization and what are

its advantages so normalization is

basically the process of organizing data

to avoid duplication and redundancy so

it's basically the opposite of

denormalization that we just talked

about in one of the previous questions

so if you just have to Define

normalization then you can see that unit

is a process of organizing data to avoid

duplication and redundancy now the

advantages of normalization are as you

can see on the screen it offers better

database organization more tables with

smaller rows efficient data access

greater flexibility for queries quickly

finds the information easy to implement

security allows easy modification

reduction of redundant data and

duplicate data more compact database and

ensures consistent data after

modification so Guys these are few

advantages of normalization now let's

move forward to our next question that

is what is the difference between the

drop and the truncate commands the drop

command basically removes the table and

it cannot be rolled back from the


database whenever you use the drop

command just remember that you know you

completely drop the complete table and

it cannot be rolled back from the

database and the truncate command

removes all the rows from the table and

also cannot be rolled back into the

database so the drop command and the

truncate command differ by this so

whenever you use the draft command you

drop the complete table and whenever you

will use the truncate command you will

remove all the rows from the table the

syntax of both the commands are almost

same the syntax of drop command is

basically drop object and object name

that is basically the table and table

name and the Syntax for truncate command

is truncate table and table name so guys

that was about the drop and the truncate

command now let's move forward to the

next question that is what are the

different types of normalization so

there are mainly four types of

normalizations that is 1nf 2nf 3 NF and

bcnf now let me explain you the

different types of normalization with an

example so guys this is the table that

we're going to consider for the example


now you basically have to apply

normalization to this particular table

now to apply normalization to this

particular table you'll clearly observe

that you know there is Alice Johnson who

has a particular address and has rented

few movies from a specific category and

the category action is mentioned twice

over here similarly David Allen's

address has been divided into two

different records and the movie is

rendered in the categories have also

been divided into two different records

right now to apply normalization to this

particular table you first have to apply

the 1nf that is the first normalized

form so for a table to be in one and if

you need to make sure that each table

cell should have a single value so

basically all the records must be unique

so as I saw in this particular table we

have redundant values in the same record

right so we're going to have each cell

with a unique record so we'll have

records such as you know Miss Alice

Johnson first read house number three

Mission Impossible and the second record

as Miss Alice Johnson first read house

number three Clash of Titans similarly

we'll have bested David Allen Third


Street 45 with Interstellar they Mr

David Allen Third Street 45 with Edge of

Tomorrow and similarly missed David

Allen's seventh annual Mission

Impossible Fallout so that's how

basically you get your table into one

and if you have records with unique

value in the complete table now as you

can see on the screen this is a table

for one and F now you have to divide

this table to 2nf so when I say 2nf that

is the second normalized form you can

divide this table into two different

tables so to have a table in 2nf you

need to make sure that you know the

database should be in 1nf and should

also have a single column primary key

since a table is in 1nf that we

considered that's applicable to our

situation now let's move forward to the

2ndf now in the 2nf you'll clearly see

that you know we have salutation full

name address and movies rendered right

now to divide this table into two

different tables you can clearly see

that you know I've added an ID to both

the tables so I've added ID salutation

full name and address and ID movie

stranded so Miss Alice Johnson staying


in First Street house number three must

have granted Mission Impossible

similarly she must have rented Clash of

Titans Mrs David Allen praying in Third

Street 45 has rented Interstellar and

Edge of Tomorrow and Mr David Allen

staying in Seventh Avenue has rented

Mission Impossible Fallout so that's how

I've divided the table into 2nf now

moving forward to 3 and F now a database

to be in real if you need to make sure

that you know your database is first

into NF and must not have any transitive

functional dependencies so for that what

you're going to do is you're going to

further divide the two tables into three

tables as you can see in the screen so

we're going to have an ID full name

address and salutation ID and also

another table with ID movies dented

column attributes and the third table

with salutation ID and salutation so

basically we're going to identify Mr

with one miss with two misses with three

and doctor with four so that's how we're

going to get our tables to 3 NF well

guys with this we come to an end of this

particular example that you know our

table has been completely normalized and

the highest normal form available for


this particular table is 3 NF now moving

forward to that final type of

normalization that is pcnf now if your

database is in third normal form and

there would be some scenarios where

anomalies would be present and if you

have more than one candid key then base

CNF comes into role when you further

divide your table so that you know there

would be only one candidate key present

so Guys these are the various types of

normalization that is one in F2 and F3

NF and B C and F so in one and if there

is no repeating groups within the rows

in 2nf every non-key column is dependent

on a whole primary key in free NF it is

completely dependent on the Primary Care

no other non-key column values and in

bcnf you have to make sure that you know

there's only one candidate key present

in the team so Guys these were the

different types of normalizations that

you need to understand about now let's

move forward to our next question that

is what is asset property in database

the asset property mainly stands for

atomicity consistency isolation and

durability it is basically used to

ensure that the data transactions are


processed reliably in a database system

so if you have to Define asset property

in a database then you have to Define

all these terms individually a stands

for atomicity so atomicity refers to the

transactions that are completely done or

failed where transaction refers to a

single logic operation of a data it

means if one part of any transaction

fails then the entire transaction fails

and the database state is left unchanged

coming to consistency consistency

ensures that the data must meet all the

validation rules in simple words you can

say that you know your transaction never

leaves the database without completing

its state third part that is isolation

the main goal of isolation is the

concurrency control and the last part

that is durability durability means that

if a transaction has been committed it

will occur whatever may come in between

such as power loss crash or any sort of

error now let's move forward to our next

question that is what you mean by a

trigger in SQL so triggers in SQL are a

special type of stored procedures that

are defined to execute automatically in

place or after data modifications it

allows you to execute a batch of code


when an insert update or any other

queries executed against the specific

table so guys there are mainly six type

of triggers that you need to understand

about that is the before insert after

insert before update after update before

delete and after delete so basically the

two main key terms that you need to

understand at the before and the after

so these are completely applied on the

insert update and the delete commands so

before insert is basically activated

before the data is inserted into the

table the after insert is activated

after the data is insert inserted into a

table the before update is activated

before the data in the table is updated

and the after update is activated after

the data and table is updated the before

delete is activated before data is

removed from the table and after delete

is activated after the data is removed

from the table so guys this is what a

trigger in SQL is it is basically a type

of stored procedures that is defined to

execute automatically in place or after

data modifications now let's move

forward to our next question that is

what are the different types of


operators available in SQL so there are

mainly five types of operators available

in SQL that is the arithmetic bitwise

comparison compound and The Logical

operators so Guys these are the main

five types of operators available in SQL

so now let's move forward to our next

question that is R null value same as

that of 0 or a blank space a null value

is not at all same as that of a zero or

a blank space a null value mainly

represents a value which is unavailable

unknown assigned or not applicable

whereas a 0 is a number and a blank

space is a character so if anybody asks

you if null values are same as that of

zero blank space please say it's no

because you know the null values is

basically anything which is unavailable

unknown and is assigned or not

applicable whereas zero is a number and

a blank space is a character

now let's move forward to a next

question that is what is the difference

between a cross join and a natural joint

the cross joint produces the cross

product or Cartesian product of two

tables whereas the natural join is based

on all the columns having the same name

and data types in both the tables the


main difference between both of them is

that you know the cross joint basically

produces the cross product of both the

tables and the natural join is

completely based on all the columns

having the same name data types in both

the team now let's move forward to our

next question that is what is a sub

query in SQL a sub query is basically a

query inside under the query where a

query is defined to retrieve data or

information back from the database so

sub queries are always executed first

and the result of the sub query is

passed on to the main query so as you

can see on my screen I have an auto

query inside which I have a sub query or

an inner query so basically this query

is assigned to retrieve data from the

database and then this query will be

executed first so if there are any

errors in this query then the complete

query would not be be executed only when

the stock query is completely executed

then the outer query will be executed

now let's move forward to a next

question that is what are the different

types of sub query now there are mainly

two types of sub queries that is the


co-related and the non-core related sub

query the correlated sub queries are

basically those queries which select the

data from a table referenced in the

outer query it is not considered as an

independent query as it refers to

another table and refers to column in a

table the non-correlated sub query is an

independent query where the output of

the sub query is substituted in the main

query so you'll have to understand the

difference between poses them if you do

not understand by definition you can

definitely go and execute the commands

write the two different types of queries

in your SQL and you'll get to know what

I'm talking about basically

non-correlated type of sub query the

output of the sub query will be

substituted into the main query and in

correlated type of sub query the queries

select the data from a reference table

in the outer query now let's move

forward to our next question that is can

you list the ways to get the count of

Records in a table now to count the

number of Records in a table you can use

various kind of queries so there are

mainly three queries that I've mentioned

over here that is Select star from table


one star means basically select all

right when you want to select all the

rows all the records from the table you

can use star next when I say select

count star from table one that is

basically you select all the records

from the table one and then you count

them and coming to the third query that

is Select rows from system indexes where

ID object ID of table 1 and indeed is

less than two that means it basically

counts the number of Records in a table

with system indexes these are the

various ways to count the number of

Records in a table now let's move

forward to our next question that is

write a SQL query to find the names of

employees that begin with the alphabet a

now to display the name of employees

that begin with a you can type in the

command like you know select star from

table name where you mention your table

name where their employee name because

I'm considering an employee table in the

scenario like a percent in codes so when

I say a person all those names starting

with a and having any letters or any

characters after that would be selected

so guys that's how you can write a query


to find the name of employees that begin

with a now suppose if you want to write

a query to find the names of employees

that end with a what you can simply do

is you can again write the similar query

like you know select star from table

name where employee name like percentage

a right so where the percentage comes

forward that means you know all the

names that start with any alphabet but

end with the a will be considered now

let's move forward to our next question

that is write a SQL query to get the

third highest salary of an employee from

an employee table now to get the third

eye is salary of an employee from an

employee table you can write a query as

you can see on the screen you can just

mention select top one salary from and

then write a sub query which says select

top free salesy from employee table

order by salary in a descending order as

amp and then again order by salary in

ascending order for the outer query so

you can write a query like this guys now

let's move forward to a next question

that is what is the need of group

functions in SQL now group functions

work on a set of rows and return one

result per group so basically some of


the most commonly used group functions

are the average count Max Min sum and

variance So when you say what is the

need of group functions in SQL the need

is basically because the group functions

work on a set of row and return one

result per group now let's move forward

to a next question that is what is a

relationship and what are the different

types of relationship so relation or

links between entities that have

something to do with each other can be

basically termed as relationships so

relationships can be also defined as the

connection between the tables in a

database right now the different types

of relationships are the one-to-one

relationship the one to many

relationship many to one relationship

and the self-referencing relationship

when you have a relationship with

between two tables at a stable a and

table B so when I say one-to-one

relationship between both the tables

table a and table b a single record in

table a will be related to a single

record in table B coming to one to many

relationship a single record in table a

can be related to many records in table


B next coming to the many to one

relationship many records in table a can

be related to one record in table B

coming to self-referencing relationship

the self-refensing relationship

basically means that you can have a

single table out of which two columns

are related to each other with a

relationship now let's move forward to a

next question that is how can you insert

null values in a column while inserting

data now to insert null values in a

column while inserting the data you

mainly have two ways that is either by

implicitly by omitting columns from a

column list or explicitly by specifying

null keyword in the values Clause so as

these are the two ways through which you

know you can insert null values in a

column while inserting the data now

let's move forward to the next question

that is what is the difference between

the between and in condition operators

the train operators basically used to

display rows based on a range of values

in a row whereas the end condition

operators used to check for values

contained in a specific set of values so

if you have to explain with an example

for between and the in condition


operators then you can use the example

on the screen you can just write a query

like in a Select Staff from students

where roll number between 10 to 50. so

all those records from the students

table would be selected whose roll

number stands between 10 to 50. coming

to The incandation Operators you can use

a query like this like you know Select

Staff from students where roll number in

8 15 25 so all those records from a

student table would be selected where

the roll number would be either 8 15 or

25 so guys that is the main difference

between the between and the in condition

operators now let's move forward to our

next question that is why are the SQL

functions used the SQL functions are

used to perform some calculations on the

data to modify individual data items to

manipulate the output to format dates

and numbers and also to convert the date

types so if you want to perform these

activities or you know if you want to

perform these actions then you need to

use the SQL functions now let's move

forward to our next question that is

what is the need of merge statement this

statement is basically used to allow


conditional update or insertion of data

into a table so it performs an update if

a row exists or an insert if the road

doesn't exist so basically the need of

merge statement is that you know it

allows conditional update or insertion

of data into a table now let's move

forward to our next question that is

what do you mean by recursive stored

procedure recursive stored procedures

refers to a stored procedure which calls

by itself until it reaches some boundary

condition this recursive function or a

procedure helps the programmers to use

the same set of code n number of times

so basically you'll first mention the

boundary condition and then you'll use

the recursor stored procedure to check

you know if it calls by itself till it

reaches the specified boundary condition

now let's move forward to a next

question that is what is a clause in SQL

now SQL Clauses basically helps you to

limit the result set by providing a

condition to the query a clause helps to

filter the rows from the end entire set

of Records so for a better understanding

the example is basically where and

having Clauses so when you write a query

you're having these two particular


Clauses you basically mention a

condition into these particular Clauses

right like where student number is equal

to two or having you know rule number

greater than 5 and so on right so that's

how you can use a clause in SQL now

let's move forward to a next question

that is what is the difference between

the having clause and the where Clause

now the main difference between having

clause and weight loss is basically that

you know the having Clause can be only

used with the select statement it is

usually used by the group by clause and

whenever grouper is not used having

basically behaves like a where Clause

coming to the where Clause the where

Clause is applied to each row before

they are part of the group by function

in a query so having Clause is basically

used with the select statement and it is

usually used in the group by Clause when

the having Clause is not used with the

group by Clause the having Clause

behaves like a where Clause so guys that

was about the difference between the

having clause and the where Clause now

let's move forward to our next question

that is list the ways in which Dynamic


SQL can be executed the ways in which

Dynamic SQL can be executed are by

writing a query with parameters using

exec and by using SP hyphen execute SQL

so there are basically three ways in

which Dynamic SQL can be executed that

is by writing query with parameters

using exig and using SP underscore

execute SQL now moving forward to the

next question that is what are the

various levels of constraints the

constraints as I mentioned before are

basically the representation of a column

to enforce data entity and consistency

so mainly there are two levels of

constants that is the column level

constant and the table level constraint

now let's move forward to our next

question that is how can you fetch

common records from two tables well you

can fetch comment records from two

tables by using the intersect statement

so the syntax of intersect statement is

as you can see on the screen it's

basically select column one column two

and so many columns from the table name

where condition basically you mentioned

condition over here when you mention the

keyword intersect and then again mention

another table name right so that is


again you mentioned select the columns

from a specific table where the

condition matches so that's how you use

the intersect command so for your better

understanding you can see the example on

the screen you can see you know that I

have used select student ID that is

basically a single column from student

then use the intersect command and then

again I have mentioned select student ID

from a different table that is exam so

that's how you can fetch comment records

from two tables now let's move forward

to a next question that is list some

case manipulation functions in SQL so

there are mainly three case manipulation

functions in SQL that is the lower upper

and the init cap now talking about the

lower function this function basically

Returns the string in lower case it

takes a string as an argument and

returns it by converting into a

lowercase the syntax of this particular

function is basically lower and in

Brackets you mentioned strings and

quotes now moving forward to the next

function that is the upper function this

function Returns the string in up

uppercase it takes a string as an


argument and returns it by converting it

into an upper case right so the Syntax

for this particular function is upper

and in Brackets you mentioned the spring

within the codes moving forward to the

third function that is the init cap this

function Returns the string with the

first letter in uppercase and the rest

of the letters in lower case so the

syntax for this function is basically

init cap and in Brackets you mentioned

the string with quotes So Guys these

were the three case manipulation

functions in SQL now let's move forward

to a next question that is what is the

difference that operators available in

SQL so the different set operators

available in SQL are union intersect and

the minus operators so let's talk about

Union first so when you consider two

queries that is the left query and the

right query and you apply the union

operation you will see that you know it

will combine rows from both those

queries you'll get an output of you know

all those records from the left table

that is basically the left query and

also from the right query that is the

right table moving forward to the next

operation it is the intersect operation


so when you apply the intersect

operation to the left query and the

right query you'll see that you know

you'll get only those rows which are

common in both the queries right so for

example you have 10 rows in the first

table and 10 rows in the second table

but the common rows in both these table

are just two rows so you'll get only

those two rows as an output to this

particular operation moving forward to

the third type of operation that is the

minus operation so when you apply left

query minus right query you'll see that

you know you'll get the only those rows

from the left query which are not

included in the right query as an output

and when you apply the operation of

write query minus left query you'll see

that you know you'll get only those rows

as an output from the right query which

are not included in the left query so

Guys these were the different set

operators available in SQL that is the

union operator the intersect operator

and the minus operator now let's move

forward to a next question that is what

is an alias command now a list name can

be given to any table or any column so


this Alias name can be referred and

where Clause to identify a particular

table or a column so that's basically an

A-list command so for example if you see

on the screen you see a query right like

select m dot employee ID

department.result from employee amp

Department as depth where m.employ ID is

equal to department.employ ID so what

I've given over here is that I've given

an alias name to the employee table as M

and for the Department table I've given

an alias name as depth so that's how you

can use the Alias command guys let's

move forward to the next question now

that is what are Aggregate and scalar

functions the aggregate functions are

used to evaluate mathematical

calculation and return a single value

these calculations are done from columns

in the table so for example if you need

to consider the aggregate functions then

you can consider the max function and

the count function as an aggregate

function now coming to the scalar

functions the scalar functions basically

return a single value based on the input

value so if you need an example for

scalar functions then you can consider

the uks and now as scalar functions as


calculated with respect to the spring so

guys this is what aggregate functions

and scalar functions mean let's move

forward to the next question that is how

can you fetch alternate records from a

table when you answer this question of

how you can fetch alternate records from

a table please make sure that you

mention a point that you can fetch

alternate because that is both the odd

and the even row numbers now to display

the even row numbers you can use the

command like you know select student ID

from select row number student ID from

student again where more row number

comma 2 equal to zero so we're using

this function of where mod row number

comma 2 equal to 0 right so when you

divide the row number with 2 and if you

get the reminder as 0 then that

particular row number would be an even

number and similarly if you get a

reminder as one then that particular row

number would be an odd number that's how

you can segregate the alternate because

that is the even number records and the

odd number records you just have to

mention the condition mod row number

comma 2 equal to 0 if or even and mod


row number comma 2 equal to 1 for board

now let's move forward to the next

question that is name the operator which

is used in query for pattern matching

the operator which is used in the query

for pattern matching is basically the

like operator so in live cooperator you

can use either the percentage sign or

the underscore sign the percentage sign

basically matches to zero or more

characters if you use the percentage

sign in the query like you know Select

Staff from students to a student name

like a percentage so all those student

names whose name starts with a and ends

with any character will be taken into

account and all the information related

to all those records will be retrieved

and coming to when you use the

underscore sign the underscore sign

basically matches exactly one character

so when you use the underscore sign in

the query like you know select star from

student where student name like ABC

underscore so all those records you know

whose student name has a characters

which match the pattern ABC and any

character present after that will be

taken into account so guys that's how

you can use the like cooperative for


pattern matching you can either use the

percentage sign with it or an underscore

sign with it now let's move forward to

the next question that is how can you

select unique records from a table well

you can select unique records from a

table by using the distinct keyword so

for your better understanding you can

write a query like you know select this

thing student ID from student right so

with the help of this query all the

unique records from the student table

will be selected let's move forward with

the next question that is how can you

fetch first five characters of a string

now there are obviously a lot of ways to

fetch the characters from a string so

for your understanding I've mentioned

two examples over here that is either

you can use the substring command or the

right command so when you use this

upstring statement you can use the

statement like you know select substring

student name one to five as student name

from student the first five characters

of student name will be retrieved from

the student table now similarly when you

use the write statement you can use the

statements like you know select write


student name comma five asteroid name

from student right so with this query

again all the first five characters of

each and every student name from the

student table would be retrieved so

that's how guys you can fetch the first

five characters of a string that is

either by using the substring statement

or the right State now let's move

forward with the next question that is

what is the main difference between SQL

and pl slash SQL now SQL as I mentioned

before is a query language that allows

you to issue a single query or execute a

single insert update delete whereas PL

slash SQL that is basically oracle's

procedural language SQL allows you to

write a full program of Loops variables

Etc to accomplish multiple operations

such as select inserts updates and

deletes so guys that is the main

difference between SQL and procedural

language SQL in SQL you just have to

write a single query to execute insert

update on delete and in procedure of

angle SQL you have to write full program

with loops and variables to perform

multiple operations like insert update

delete and selects now let's move

forward to a next question that is what


is a view of view is basically a virtual

table which consists of a subset of data

contained in a table since views are not

present it takes less space to store and

Views can have data of one or more

tables combined based on the

relationship so as you can see on the

screen I have two tables of you know n

number of rows and columns now once I

execute a query to form a view you can

clearly see that you know it has

combined The Columns and the rows from

both the tables and has created a view

of both of these tables into a single

table that's what a view is now let's

move forward to the next question that

is what are views used for so views as I

just explained basically refer to a

logical snapshot based on a table or on

any other view it is used for

restricting the access to data making

complex queries simple ensuring data

Independence and also providing the

different views of the same data so

that's what views are used for now let's

move forward with the next question that

is what is a stored procedure a stored

procedure is basically a function which

consists of many SQL state statements to


access the database system several SQL

statements are Consolidated into a

stored procedure and are executed

whenever and wherever required which

obviously saves time and we can avoid

writing code again and again so with the

help of stored procedure you can make

sure that you know several SQL

statements are executed again and again

and you don't have to write the query

for it again because you know you if you

just have a stored procedure for it it

will automatically execute the queries

for you now let's move forward with the

next question that is list some

advantages and disadvantages of stored

procedure let's talk about the

advantages first so stored procedure can

be used as a modular programming which

means create one store and call for

several times whenever it is required

the supports faster execution and it

also reduces Network traffic which

provides better security to the data

coming to the disadvantages of stored

procedure the only disadvantage of store

procedure is that it can be executed

only in the database and utilizes more

memory in the database over so guys that

was about the advantages and


disadvantages of stored procedures now

let's move forward with the next

question that is list all types of the

user defined functions so there are

mainly three types of user-defined

functions that is the scalar function

the inline table valued functions and

the multi-statement valued functions so

you mainly have to mention these three

functions when you're asked about the

different types of user defined

functions next let's move forward and

understand what do you mean by collation

so collation is defined as a set of

rules that determine how data can be

sorted as well as compared so character

data is sorted using the rules that

Define the correct character sequence

along with the options for specifying

case sensitivity character width and Etc

so that's what a collision is guys it is

basically a set of rules that determine

how data can be sorted as well as

compared now let's move forward with the

next question that is what are the

different types of collation sensitivity

so the different types of collation

sensitivity are the case sensitivity the

Kana sensitivity the width sensitivity


and the accent sensor activity so Guys

these are the mainly four types of

sensitivities of collation so I hope

that you've understood till now next in

this session let's understand what are

the local and the global variables now

talking about local variables first

these variables can be only used or

exist only inside the function these

variables are not used or can't be

referred by any other function right so

whenever you want to use local variables

then you need to understand the fact

that you know they can be only used or

exist inside a single function and they

can't be referred by any other function

coming to Global variables these

variables are the variables which can be

accessed throughout the program so

Global variables cannot be created

whenever the function is called but yes

they can be accessed throughout the

program so guys that was about the local

and the global variables next let's move

forward and understand what is auto

increment in SQL Auto increment keyword

allows the users to create a unique

number to get generated whenever a new

record is inserted into the table so

this keyword is usually required when


our primary key is used and auto

increment keyword can be only used in

Oracle whereas the identity keyword can

be used in the SQL Server so that was

about Auto incremented SQL guys next

let's understand what is a data

warehouse data warehouse refers to a

central repository of data where the

data is assembled from multiple sources

of information those data are

Consolidated transformed and made

available for the mining as well as to

online processing Warehouse data also

has a subset of data called the data

Mass so data warehouse can be understood

as a central repository of data where

the data is assembled from multiple

sources of information so guys that was

about data warehouse now let's move

forward and understand what are the

different authentication modes in SQL

server and how it can be changed the

different authentication modes in SQL

Server are basically the windows mode

and the mixed mode so these two modes

are basically used in SQL windows and to

change the authentication modes in SQL

Server what you can simply do is you

have to follow the steps that are


mentioned on the screen that is you have

to first click on start then go to

programs and go to the Microsoft SQL

server and click SQL Enterprise Manager

to run SQL Enterprise Manager from the

Microsoft SQL Server program group now

to change the authentication modes in

the SQL Server you can follow the steps

that I've mentioned on the screen that

is you have to click on start go to

programs go to Microsoft SQL server and

click SQL Enterprise Manager to run SQL

Enterprise Manager from the Microsoft

SQL Server program group then select the

server from the tools menu and select

SQL Server configuration properties and

choose the security page right so that's

how you can change the authentication

mode in the SQL Server guys now let's

move over with the final question in the

session that is what are stuff and

replace function so talking about this

tough function first this function is

basically used to overwrite existing

characters or insert a string into

another string so the Syntax for this

function is basically stuff string

expression start lens and replacement

characters where the string expression

is basically the string that will have


characters instituted start represents

the starting position the length refers

to the number of characters in The

String which are substituted and the

replacement string are the new

characters which are injected in the

spring coming to the replace function

this function is basically used to

replace the existing characters of all

the occurrences so the Syntax for this

particular function is that replace

string expression search string

replacement string where every search

string in the string expression will be

replaced with the replacement string I

hope I am clear with the staff function

and the replace function so Guys these

were the questions that could be asked

in your interviews

[Music]

now what exactly is data science now

data science in simple terms is the

process of deriving useful insights from

data in order to solve your ball

problems or in order to grow a business

now data science was introduced because

we are generating an immeasurable amount

of data for example there's a fact that

we're generating more than 2.5


quintillion bytes of data every day and

at this pace it's only going to grow

because right now everything runs on

data so the idea behind data science is

to take up all this data and you know

derive useful insights or derive

knowledgeable insights from this data so

that you can grow your business or you

can solve a problem that's what data

science is all about the data is the key

in data science and since we are

producing so much data is the perfect

time for you to learn data science and

data science basically covers artificial

intelligence machine learning natural

language processing or these processes

are covered under data science so that

is one of the reasons why data science

has become so popular because of the

amount of data we're generating we need

methods and technologies that can handle

so much data and they can you know

derive something useful from the data so

that's a small introduction to data

science and if you guys want to learn

more about data science I'll leave a

couple of links in the description box

now let's move ahead to our topic of

discussion first we'll understand why we

need SQL for data science


so like I said data science is basically

all about deriving useful insights from

data data science involves extracting

processing and analyzing tons and tons

of data at present what we need are

tools that can be used to store and

manage this vast amount of data now this

is where SQL comes in SQL can be used to

store it can be used to access and

extract massive amounts of data in order

to carry out the whole data science

process more smoothly so SQL as

acquiring language it can be used to

perform a lot of querying operations a

lot of search operations extractions and

editing and modifying your data so we

need a huge management system and along

with that we need a language that can

perform all the operations that we want

to do on our data that's why SQL comes

in so like I said we'll be using MySQL

today and let's understand why I've

chosen MySQL now first of all MySQL is

very easy to use you have to get only

the basic knowledge of SQL right you can

build and interact with mySQL with just

a few simple SQL statements right an SQL

statements are quite easy like they're a

lot like your English language I feel


like it's the most basic and the most

understandable language there is

querying language

apart from this it is also very secure

actually MySQL consists of you can say a

solid data security layer which will

protect all of your sensitive data or

your confidential data from any

Intruders passwords are encrypted in

MySQL so that's a good advantage of

using MySQL apart from that of course

it's open source so it's free to

download and to use you can just go to

the official website and download it in

a matter of minutes then of course it is

scalable as well right it can handle

almost any amount of data right it

supports large databases up to as much

as 50 million rows or more right that's

the amount of data that you can store in

MySQL and the default size limit is

about 4 GB if I'm not wrong and you can

also increase this number to a

theoretical limit of around 8 DB of data

I think you'll have to pay a little bit

of money for that but I feel like 4GB is

a lot first of all to have a data set of

that size

then another important point is that

MySQL follows a client server


architecture so this is where you

basically have your database server

which is your MySQL and you have many

applications and programs as your

clients right and these communicate with

the server this is where they query data

they save changes they update the data

and all of that

not only this MySQL is compatible on

many operating systems it is easy to run

on a lot of operating systems such as

Windows Linux Unix and so on now MySQL

actually provides a functionality that

the clients can run on the same computer

as a server or they can even run on

another computer so basically

communication via a local network or the

internet another important point is that

there are quite a number of apis and

libraries for the development of MySQL

applications so basically it has support

for multiple programming interfaces

right so client programming you can use

languages like C C plus plus Java Perl

PHP Python and so on and all these

languages are easily compatible they

provide API so that you can integrate

and you can perform or you can build the

applications using these languages and


since python is one of the best

languages for data science MySQL is

perfect for data analysis storing data

and querying data you can easily work

with mySQL and python to build

applications and query data and all of

that

right apart from that it is also

customizable like I said and it's also

platform independent right it's not only

your client applications that can run

under a variety of operating system but

MySQL itself can be executed under a

number of operating systems the most

important ones are your Mac operating

systems Linux Microsoft Windows and so

on apart from that we also have speed

right MySQL is considered a very fast

database program and this speed is

actually being backed up by a large

number of Benchmark tests and apart from

that it's highly productive because it

uses triggers it uses stored procedures

and Views and this basically allows the

developer to give a higher productivity

so these are a few reasons why you

should go with mySQL right I feel it's

one of the most easiest to use and it's

one of the most compatible databases

that are there


now let's move on and discuss a couple

of Basics about MySQL so we'll discuss

the data types which come under MySQL we

have numeric we have character string we

have bit string Boolean date and time

and time stamp and interval right under

numeric it includes integers of various

sizes there is a floating point of

various precisions and formatted numbers

under character strings these data types

either have a fixed or they have a

varying number of characters now this

data type also has a variable length

string which is called character large

object which is used to specify columns

that have large text values so it

supports large text values as well apart

from that there is bit string now these

data types are either of a fixed length

or varying length of bits now there is

also a variable length bit string data

type which is called binary large object

now this is available to specify columns

that have very large binary values such

as you know maybe images and so on then

we have the Boolean data type now this

data type as the name suggests itself it

has true or false values and since SQL

has null values a three valued logic is


used which is unknown that's the third

value

then we have date and time so the date

and time is like any other date variable

the date data type has your month and

day and the normal date form and

similarly the time data type has

components like R minute and second now

obviously these formats can be changed

based on your requirement

next we have the timestamp and interval

data type so the timestamp data type

includes a minimum of six positions for

decimal fractions of seconds and an

optional with time zone qualifier in

addition to your date and time Fields

okay so the interval data type will

basically mention a relative value that

can later be used to increment or you

know decrement an absolute value of time

or date or any of that sort or basically

a time stamp right so you can increment

or decrement any absolute value using

the interval data type so guys this was

a little bit information about the

different data types that are there now

let's discuss a little bit of basics of

SQL like I said I'm just going to brush

up a couple of topics because I'm hoping

that you all have a good understanding


of the querying language so let's just

brush up a little bit so first of all we

have the First Command which is create

database now this is a very general

purpose Command right it basically

creates a new database for you so the

syntax is just create database and the

name of your database then once you

create it in order to initialize and use

it you just use the command use and the

name of the database that you created

and remember that at the end of each

command you have a Terminator which is a

semicolon and also your commands are

usually written in capital letters so

that you can differentiate your commands

from your table columns or table names

and all of that so it's a good practice

if you write all your commands in

capital letters

next we have create table now tables are

the most important part of a database

right so create table is a simple

command that will create a new table for

you and it can contain a lot of data

variables of different data types right

so the syntax is simple the command is

creatable the name of the table you want

to create and then within the table


whatever variables you want you can

mention the name of the variables with

their respective data types like for

example if your variable is age then

your data type will be an integer or

something like that similarly you can

add another variable like name and you

can have the data type as a character so

it's as simple as that it's very

understandable the language and then

let's talk about insert into now this

command is used to insert new data into

your table now usually what happens is

when people insert values into the table

they forget the data type that they've

defined under that particular variable

so remember that the values that are

inserted it must align with the defined

data types

so for example if your variable is age

and instead of putting your numerical 3

you've put your character 3 basically

you've typed out t h r e e and that's

not going to work because you already

defined your age variable as integer so

you'll get an error there so make sure

that the values that you are inserting

into your variable are of the same data

type as you've defined your variable as

okay so make sure that happens now these


are very simple things guys I'm sure you

guys are aware of this now let's look at

our next command which is Select so this

is one of the most important commands

when it comes to SQL for data science

and because mainly it's all about

extracting useful insights and

extracting particular type of data from

your database right we'll see how often

we'll use this command when we perform

our demo today this is one of the most

simplest and in fact it's one of the

most important commands in SQL okay so

basically select will select a specified

table or a column and it will extract

the values from it okay so select star

from and table name is your syntax now

we'll be using this in the demo so don't

worry if you do not know exactly what

this does just remember that your select

command is for extracting data from your

table

next we have the update command so

update will basically allow you to

modify any values that are stored in

your table and the where Clause here

will select the variable or value that

you want to change so it's basically

it'll highlight the variable or the


value or I'll try to identify the value

that you want to change next we have the

delete command now delete will basically

delete data from your data set or from

your table as the name itself suggests

so delete from the name of your table

and where with the condition it's as

simple as that next we have a drop table

so this command is basically used to

delete a table and all the rows in the

table so your table will get deleted

from your database that's what happens

with drop table

these were a couple of commands that I

thought you should brush up on I'm sure

you guys are already aware of these

commands but in case there are a few few

who don't know much about SQL I'll leave

a couple of links in the description box

you can go through those videos and then

maybe come back to this if you're

specifically looking for SQL for data

science

now let's get started with our demo

which is quite interesting

so guys with this demo I'll be using the

MySQL workbench so it's quite easy to

install it'll just take like 15 to 20

minutes I'll leave a link in the

description box we have a short video


where it may showing you how to install

the whole workbench so once you've

installed MySQL we'll start by creating

a database and we'll import a data set

into our workbench so I'm going to

import a existing data set right I'm

doing this because we are doing a more

advanced tutorial this is not about

creating tables and you know extracting

values from tables instead this is about

deriving useful inside from your data so

usually for data science you don't have

to sit down and create tables and you

know do those basic commands instead you

have to explore the data variables so

usually there's a humongous data set

that needs to be explored and analyzed

in order to derive something useful from

it right so that's what we're going to

do today so I've already imported a CSV

file let me show you what the file looks

like

so this is our CSV file and this

basically contains details about

employees

so basically the name of the employee

title is the job title of the employee

department is the department that the

employee is working in then we have the


annual salary we have the hiring date we

have the start date in the present

position we have the salary and we have

the employment category whether you're

full-time employee or whether you're

part-time employee

so our data set has around 32 000

observations right so this is a very

huge data set and I basically downloaded

from the internet you can find a lot of

data sets on the internet and you can

perform all of the data analysis in no

time

so if you don't know how to import a

data set in your MySQL workbench and

I'll quickly show you how it's done so

I've already created a database here now

creating a database is as simple as this

right you just have to do create

database and name of the database let's

say tutorial

and then if you want to use it you just

use the command use

tutorial

right so basically tutorial database

gets activated now all you have to do to

run is you have to use

this right use tutorial so we've

basically activated our database now for

this tutorial I've already created a


database so I'm going to use that

database itself

name of my database is students

all right so let's activate this

database right now in this I have a

couple of tables and we are going to be

focusing on this table employee details

so this is the table that I imported so

guys for those of you who don't know how

to import a CSV file into your MySQL

workbench all you have to do is go to

tables right click on any table and go

to table data import wizard

right click on this and browse for your

CSV file okay just to take an example

I'll consider this CSV file I'm not

going to import the CSV file that we're

going to be using right now because that

is a very very huge CSV file and it'll

take a lot of time for me to import that

CSV file into the workbench to save up

on some time I'll import a small CSV

file and I'll show you all right so I'm

selecting this file students marks let's

open it

right and go to next

after that create a new table now

basically what you're doing here is

you're going to create a new table that


corresponds to all the columns that are

there in your CSV file either you can

create a table on your own and click on

use existing table or you can allow

MySQL workbench itself to create a new

table for you that's what I'm going to

do because obviously it's simpler then

click on next

so this is basically all the fields that

are there in my CSV file it will collect

all the fields in my CSV file and it

will create a table out of it right this

is my CSV file basically it has name

gender date of birth math physics

chemistry and all of that these are just

records of students and their marks then

if I click on next

and next again

yeah data gets imported next five

records are imported click on finish and

refresh

here you see student marks so this was

the CSV file that I just imported into

my SQL workbench so guys that's how you

import a CSV file as a table into your

MySQL workbench so if you want to see

this table right the CSV file that we

imported as a table all you have to do

is Select

star from and the name of the table it


is student underscore marks

so let's just run this

so here you can basically see the entire

CSV file that we imported into a table

so guys that's how simple it is to

import a CSV file into your MySQL

workbench in order to perform data

analysis so now let's clear this up

so for this demo like I said we'll be

using employee details data set

this is a very huge data set and let's

just get started I've already imported

the data set here as a table right if

you take a look at this employee details

so these are the columns in my table we

have name of the employee title is the

job title of the employee department is

the department he works in salary annual

salary then we have hiring date start

date salary Basics and we have

employment category

all right so let's start by performing

some sort of data analysis so first what

we'll do is let's just view the entire

table that we have for that all you have

to do is Select star from

the name of the table employee details

is the name of the table in my case so

I'll just run this command


right

so this is the entire table that just

got loaded all right so this will just

extract your entire table for you since

I did select star from and name of the

table so my entire table is extracted

here right if you take a look at this

the whole table is being extracted here

right

now let's do something a little more

complex

now let's write a query to find the

salaries of all the employees for that

what you have to do is select again now

name of the column that has the salary

okay in our case it is salary annual

right

so let's write that down salary

annual

right

from

the name of your table employee

details

okay so let's run this

so this query basically just gave me the

salary column in my table right salary

annual this is the salary of all the

employees that are there

right it's as simple as that

now let's write a query to display the


unique designations for the employees

basically you need job roles we'll

display

so for that

again we have select because we're

extracting then we have a keyword called

distinct since we are trying to display

the unique designations it'll just take

the designations that are unique it

won't take your repetitive designations

for example there might be 10 employees

who are working as data analysts so

we'll just consider that as one so we're

just extracting the unique designations

for the employees that's why we have the

word distinct here next a job title is

in the variable title so that's why I've

written title here and then

we have from and the name of your table

right let's run this command

so here you can see that there are

different job titles in our data set we

have Sergeant we have police officer we

have Chief contractor expeditor we have

civil engineer concrete laborer we have

traffic controller pool motor this is

police officer and this is police

officer assigned as detective wow that's

interesting right so basically this


query gave us the unique job roles that

are there in our data set now let's try

something else let's write a query to

display the unique departments with

their jobs so let's extract that so

select again since we are trying the

unique we are going to use a distinct

keyword and we are going to extract the

unique departments and the job titles

and from the name of the table

so let's run this code

now under Police Department we have

different job titles that's why this is

repeated here and we have police officer

then there is Fleet and facility

management under which we have a chief

contractor as expeditor underwater

Management Department we have a civil

engineer and so on right so guys this

query was pretty simple it just gave us

the distinct departments according to

their job titles

now let's perform another query we'll

write a query to list the employees who

are working in a particular Department

let's say the fire department again

since we're extracting we'll use the

keyword select

after that select star from and the name

of your table
where so this is where the where Clause

comes right we're trying to identify a

particular department so we'll put where

depart meant in the name of the

department that we're looking for

let's say fire department that sounds

interesting so let's run this

all right

so here you can see that we've just got

employee details of all the employees

that are there in the fire department

these are their salaries these are the

dates that they were hired on and apart

from that this is the employment

category full-time part-time salary

basis is whether you're getting paid

hourly or whether you're getting paid on

a daily basis so these are the details

of all the employees that are working in

the fire department if you see that here

it's entirely Fire Department

so that was also quite simple so this is

how SQL is the language is very very

simple because it's pretty

understandable like you can read the

statement and you can understand what

exactly I'm trying to extract or what

exactly I'm trying to do

next let's try to do something


interesting let's say that we want to

write a query to list the employees who

do not belong to a particular Department

let's say that we're trying to list out

the employee details of employees which

are not in the police department so for

that it's quite similar to our previous

query so you write select star from name

of your table again

where

Department

not in that's the only difference okay

not in and the name of the department

that you want to exclude so this time

let's say police department so we want

only details of employees that are not

there in the police department so let's

run this

so all the Departments here will have

everything apart from your Police

Department okay so we have fire we have

water management we have law we have

streets and sand we have finance

department we have Fleet and facility

management and all of that so basically

we excluded our police department and

printed out the details of all the

employees which are in every other

department apart from the police all

right so now let's write a query to list


the employees who joined before a

particular date so for that again we'll

start from select star

from name of your table

right and

we'll add the where clause and here

we'll mention our original hiring date

since that's the name of the variable

that has the higher dates in it

let's keep it less than

a particular date okay let's choose

first of January 2000.

let's run this code

and so when you run this code you'll

find all the employees that were hired

before 2000 so if you see original

higher date all of this is before 2000.

some of them were in 1994 1996 1984 and

1987. so the only four employees who

were hired before the year 2000

basically before the 1st of January

2000. now let's try another query let's

write a query that will display the

average salaries of all the employees

who work at a particular Department okay

let's choose the surgeon department so

basically we're going to display the

average salaries of all the employees

who are working as surgeons so for that


again it starts from select

since we have to calculate the average

salaries we'll use a function called

average which is a predefined function

in SQL and average of which column it is

a salary column

salary

annual

and let's mention the name of the table

from

employee detail

thumb Arrow let's write down the whole

statement and then we'll see what the

error is this and we are going to select

the job title as a surgeon

basically the average salary of a

sergeant

let's run this first and we'll find out

what the error is okay there is no error

I have no idea why I'm getting this

so the average salary is around 1 lakh

6000 and change right for a surgeon

so now let's try another query what we

can do is we'll write a query to display

the details of a particular employee

some name Will select at random okay so

select star from name of your table

employee details

where name is equal to

let's look for a particular name


Ahmad Syed okay so this is the name of

the employee let's paste that name over

here

right hopefully this should give us an

output let's run this

so now we have the details of this

particular employee whose Ahmad Syed his

title job title his Department his

salary all the details about him so we

just printed all the details about a

particular employee

now let's try something else let's write

a query to list the employees whose

salary is let's say more than 3 000

after giving a 25 increment to their

salary

now let's do a little bit of math so we

list down employees whose salary is more

than 3000 after giving them a 25

increment so let's write down a query

for that

so again start off with select star from

the name of your table where here we

specify the condition

basically after giving them a 25

increment 1.25 into the salary

so salary

annual and after giving them a 25

increment their salary should be at


least three thousand all right so this

is exactly what we're doing here let's

run this code and let's see if we're

getting anything

so here are the employees whose salary

is more than three thousand dollars

after giving them a 25 raise so

basically these guys are promoted this

is a list of all the employees

so that's quite simple guys it's basic

math implemented in one line of code

that's how simple SQL is and a lot of

data scientists require this kind of

tool because querying even your

complicated math and even complicated

things from your database becomes very

easy when you make use of SQL languages

it becomes extremely easy to even do the

complex things now I just did this in

one line so now let's try something else

let's write a query to list the

employees whose salary is less than a

particular number okay let's say Less

Than 3 500 dollars so let's

write a query basically for employees

whose salary is less than three thousand

or three thousand five hundred

where

salary

annual is less than let's say 3500.


so let's run this line of code

all right so we have a couple of people

whose salary is less than three thousand

so we have 2756 like maximum of these

people have 2756.

okay so basically this is a list of

employees whose annual salary is less

than three thousand dollars

that's also quite simple to do it's just

one line of code now let's try something

else we'll write a query to list the

names and a particular set of details

about an employee who's joined before a

particular date let me write it down for

you and then we'll understand what

exactly I'm doing

so select okay now we'll Define a

variable so that we can basically

extract a number of columns okay so let

me write this down and then I'll tell

you what exactly I did here name and

let's also get their salary right

original

hiring date

then we'll also get the salary

from

the name of the table

where

the hiring date


let's say was lesser than I'll give a

random number 0 1 0 2 2008.

now what exactly I'm doing here is I'm

basically listing out the name of the

employee the hiring date and the salary

of all the employees that have joined

before a particular date okay basically

before this date that's what I've done

here

let's run this line of code and let's

see if it works

right

so here we have the name the hiring date

and the salary of individuals that have

joined before a particular date in 2008.

so it's as simple as that

now let's write a query in SQL to list

all the employees who joined on a

particular date okay let's say we want

the details of all the employees who

joined on October of 2013 or something

like that for that

again it starts off with select star

from

the name of the table

we'll add the where Clause along with

the hiring date original higher date

a particular date let's say 0 8

20 13.

let's run this line of code


so basically we list down employees that

were hired on this particular date okay

these are details of all the employees

that were hired on the same day so we

have around six employees that were

hired on the 8th of 2013 some date right

so guys that's what you see SQL is a

very easy language you just have to

understand what you're trying to extract

that's all you just have to know like

five to ten basic commands and these

basic commands can do wonders they can

extract and manipulate data in such a

way that you know you can perform proper

data analysis data processing and so on

now let's try one last query let's write

a query to list the employees whose

annual salary is within a particular

range for this again we have select star

from name of the table

employee details and

let's add the where clause and here we

will say salary

annual is between

us another keyword so between two

numbers okay let's say between uh 24

000 dollars

and let's say 50 000.

right let's run this line of code


all right so here you can see that all

of these employees have a salary range

between 25

000 and 50 000. so 43 201 we have forty

two thousand yeah forty four thousand we

have forty five thousand forty eight

thousand is the maximum salary all right

so this is basically how you perform

querying using SQL

[Music]

what is postgres SQL now postgres sequel

is an open source object relational

database system with a 30 plus years of

active development in the industry so

basically if you have to understand

postgresql guys a post SQL is basically

a programming language or maybe you can

understand that you know a language to

which you can handle open source

relational database systems and then

handle databases

postgresql is world's most advanced open

source relational database so guys this

is a really great topic to start

learning about databases so if I have to

just Define postgres SQL for you then

you have to understand these two points

over here that it is open source and it

is used for handling databases in the

form of object relational database


system so the data present in the form

of relational database but yes it is

object oriented that's where postgresql

comes into picture now since postgres

SQL is so popular in the industry next

let's look into the features of postgres

SQL so the features of postgres SQL are

as you can see on my screen that is

basically the data types so data

Integrity performance reliability

security and extensibility so talking

about data types when I say data types

what I mean by that is postgres SQL

provides various kinds of data types to

store data in any format such as you

know integer numeric data type Json XML

file may be in the form also of point

line Circle polygon and also you can

have custom data types so there are

various kind of data types like you know

the Primitive one the structure the

document geometry and customizations so

we'll not get into the depth of you know

the different data types related to

postcode SQL you can go to their

official document and check what are the

different data types that you know

postgres SQL provides well I would leave

that to you moving on to the next


feature data Integrity so when I say

data Integrity what I mean by that is

you know your data is secured so

basically whatever data that you have

it's made sure that you know it's

there's no redundancy and then it's

stored in the proper format with the

help of you know various constraints and

keys used in databases like primary key

for foreign Keys exclusion constraints

unique constraints explicit locks and so

on right so that's how basically your

data Integrity is met coming to the next

feature that is performance now

performance is something that's very

important to all of us right because all

of us want a good performance for any

action that we do in Industry basis

right now since postgres SQL meets with

good performance standard that clearly

implies that you know it has been used

for more than 30 plus years of active

development now to enable performance in

post the SQL we have various features

like you know indexing or maybe

sophisticated query planner

multi-version concurrency control table

partitioning just-in-time compilation of

expressions and so on now moving on to

the next feature that is reliability now


postgresql also proves itself in the

factor of reliability that is because

you know it has various functionalities

like write ahead logging replication

point in time recovery active standbys

and table spaces finally coming to

extensibility now of obviously any

database that you wish to use you would

obviously want to extend it to maybe any

application that you might be using in

the industry or maybe in your company or

also on an individual basis well

postgresql provides all those

functionalities with the help of stored

functions and procedural language

foreign data wrappers and many

extensions that you'll see further in

the session so Guys these were the main

six features of postgres SQL that is

data types data Integrity performance

reliability security and extensibility

so now that you know what is postgres

SQL let's next look into how you can

install postgres SQL so what I'm going

to do is I'm going to install postgresql

on windows so apart from that if you

want to install postgres SQL on any

other operating system well the steps

are really simple and the steps are


almost same so let's get started by

installing postgres SQL so what I'm

going to do is let me open my Google

Chrome and then let's say I just type in

postgres SQL download right so once I

type in in you have to first to go to

the official website of this that is

postgresql.org download so this is where

basically you'll have to go to first

start installing postgres SQL so what

I'm going to do is basically I have to

install on Windows right so over here

you have to start choosing your

operating system so if you wish you

install a Linux let's say you know

Ubuntu then you would choose this option

but since I'm going to install on

Windows I'm going to Simply choose this

particular option so if I click on

Windows over here you'll be next

redirected to this particular page now

this is the page basically you have to

install the installer right so basically

every operating system that you choose

the official website of postgres SQL

will redirect you to a particular page

which will have this particular

installer so over here you can see that

I have the windows installer and then I

have to install and then you can see the


platform support right so what I'm going

to do is I'm gonna just click on this

option download the installer

now once I click on download the

installer this is where basically you

have to choose your configuration right

so either it is Linux or Windows or Mac

OS that's completely your choice on what

operating system that you wish to choose

since I've been installing on Windows

I'll choose Windows 64-bit right so I'm

going to choose this particular option

of download and please remember with the

fact that you know try to install the

most latest version so that you can get

the maximum features that you want so

I'm going to install the 11.4 version

word for Windows 64-bit right so I'm

going to just click on download over

here and then you see that you know

you'll be redirected to this particular

page that you know thank you for

downloading postgres SQL and also on the

left hand side you'll see that you know

postcode SQL is getting downloaded right

so let's wait for it to download

all right so as you can see on my screen

it has got downloaded so I'll just

double click it so that we can open


now once you double click on the setup

you'll see that you know this particular

dialog box opens which says welcome to

postgresql setup blizzard right so now

you just have to click on next and then

you have to choose the installation

directory I'm gonna let it be as it is

so by default minus C program files

postcode SQL and level so that will be

basically my installation directly and

then I'll click on next Once I click on

next you'll get an option basically on

the various components that you wish to

install well I wish to install all of

them so basically I'm installing the

server the PG admin the stack Builder

and the command line tools so now over

here let me tell you that you know the

PG admin is the official GUI for

postgres SQL so we'll be working on the

GUI for this particular session so I'm

going to just let it be as it is since

all of them are checked in and then I'll

click on next Once I click on next I

have to next choose the directory under

which I'll basically store my data right

so this is basically my data directory

that is C program files post the SQL 11

data so I'm going to let it be as it is

and then I'll click on next Once I click


on next I have to mention my password

for the database super user so just

mention the password any password that

you wish to and please remember the fact

that you know you have to remember this

password to configure your server right

so do not forget this password and

please make sure that you remember this

password after that just click on next

again and then you have to select the

port number so I'm going to let it be as

a test so basically my server will run

on the port 5032 and then I'll click on

next Once I click on next you'll see

that you know I can choose the default

local to be used by the new database

cluster so I'm going to let it be as it

is and then I'm going to click on next

Once I click on next you'll see that you

know basically the following setting

will be used for installation that is

basically whatever you have selected

till now will be shown over there that

is the installation directory the server

installation directly the data directory

the database Port the database super

user and so on right and then I'll click

on next over here again and now you'll

see a confirmation that you know the


setup is now ready to begin installing

postgresql on your computer if you're

fine with it you can just click on next

else you can just go back make the

changes and then again come back to this

particular dialog box right so I'm fine

with it so I'll just click on next over

here and then you'll see that you know

post the SQL is getting installed on my

system so let's wait for it to install

all right now once the installation is

done you get a confirmation wizard that

you know the setup is finished

installing postcode SQL on your computer

right so you can just click on finish

and then if you want to launch the stack

builder at your exit you can just check

in this box but I'll just uncheck this

particular box and then I'll click on

finish once I click on finish basically

guys your installation is done now if

you search for postcode SQL on your

system you'll clearly see options of the

various stuff that we have installed

right so as you can see on my screen we

have PG admin we have the SQL shell we

have the documentation the PG admin

documentation the release notes and so

on right so what I'm going to do is I'm

going to open the SQL shell and also the


PG admin so let me just open

all right now once you open the PG admin

you basically are asked for the master

password so if you remember while

installing I asked you to enter a

password right so that's basically the

password that you have to mention over

here so I'll just mention my password

right now once the password is entered

you'll clearly see that you know we have

a server and then automatically the

server gets connected to databases and

the super user database that is postgres

right under this particular database

what we're going to do is we're going to

basically use the different commands

that is this different SQL command

categories and then we're going to

create a schema table and then we're

going to choose how we can play around

with databases right so on the SQL shell

what you can do is you can again

similarly connect to the server so you

just basically have to click on enter

because you're connecting your server on

the localhost so I'll just click on

enter that the database basically the

super user database is postgres so click

on enter again the port has to be the


same that is 5432 I'll click on enter

again the username will be postgres so

I'll just click on enter again and

password is basically what password you

mentioned while installing right so

you'll mention the same password and

then you'll see that you know once you

hit on enter you'll clearly see that you

have been redirected to postgres so

basically that's how guys you can

configure server either on the PG admin

and also on the SQL shell

so guys that was about installation of

postcode SQL on Windows I hope you've

understood all the steps so now that

you've installed postgresql on your

system next let's look into the SQL

command categories so as I said there

are mainly four command categories that

is the data definition language commands

the data manipulation language commands

the data control language commands and

the transaction control language

commands right so basically Guys these

are the main four command categories of

SQL that is the ddl commands the DML

commands the DCL commands and the TCL

commands the ddl commands basically

consists of the commands which can be

used to define your schema right so you


can create a table you can create a

schema you can create a view and so on

right so basically all those commands

which Define the database of the schema

basically how your data has to be

represented and what would be the very

stable so maybe let's say which table

will be related to other table and so on

will be all under this particular

section that is the data definition

language commands coming to data

manipulation language commands the DML

commands basically consists of those

commands which deal with the

manipulation of data present in the

database so all the manipulation that

you'll do in your databases will be with

the help of the data manipulation

language commands coming to the data

control language commands the data

control language commands basically

includes those commands which deal with

the rights permissions and other

controls of the database system you're

like you know which database has to be

granted to any specific user or maybe

that particular database will be open to

public and so on and finally coming to

transaction control language commands so


the transaction control language

commands basically include those

commands which mainly deal with the

transaction of the database so Guys

these are mainly the four different

command categories that is the ddl DML

DCL and TCL so without wasting any

further time let's look into the ddl

commands now what I'm going to do is I'm

going to show you how you can write

commands on the SQL shell and then I'm

going to use the PG admin right so it's

really simple PG admin is the GUI for

postgres SQL enter today's market in

Industries people are mostly using PG

admin because you know they can connect

this particular database to various

other external tools also so that you

know they can manipulate the data and

maybe they can generate reports and so

on right so I'm going to initially show

you on SQL shell for few commands and

then I'll completely shift over to the

GUI so now let's say you know you want

to create a schema how do you think you

can create a schema well the command is

really simple for that you'll have to

use create right so what you'll do is

basically you'll type in

create schema and let's say we mentioned


the schema name to be information right

right so I'm going to use caps so that

you understand that you know that's a

particular syntax and the small case let

us to understand that's the name that

I'm giving and that's completely your

choice on how you wish to do and then

I'll end with a semicolon and click on

enter once I click on enter you'll see

an output that you know creates schema

that means you know a schema has been

created now if I go back to my PG admin

and then let's say you know I just

refresh over here so automatically

you'll see a schema that is information

right so basically whatever I've created

in SQL shell is automatically seen in PG

admin right so that's the reason I told

you it's easy to visualize and use GUI

over here now similarly if you wish to

create a new scheme over here what you

can do is you have this schema option

right you right click over here choose

create and choose create schema

automatically you just have to mention

the name let's say I mentioned sample

and then I'll leave the other details to

be the same that the security default

Privileges and SQL right so in SQL


you'll basically see that you know the

syntax that I just mentioned in this SQL

shell that is create the schema and then

schema name and authorization postgres

that's basically our database super user

well that's by default in SQL shell

because you know we are already under

postgres so that's the reason we didn't

have to give it over there so I'll just

click on Save and then once I click on

Save you'll automatically see that a

schema has been created that is

basically sample so now I have the

information schema the public schema and

the sample schema and the public schema

is created by default and the

information was the one that I created

in SQL shell and the sample is the one I

created in GUI so you see right how

simple it is now if you're getting

confused how you can write queries in

GUI well don't worry we have a query

tool also so if I right click over here

and then if I choose query 2 you'll see

that you know automatically you'll get a

workspace where you can basically put

all your queries I'm not going to do

that now next what I'll do is let's say

you know we want to use this particular

schema so what I'll do is I'll just type


in the query set

search path to and then I'll mention the

schema name right so I'll mention

information over here so automatically

you'll see an output that you know it is

set to information right so whatever

actions that I wish to perform like you

know creating tables or maybe views and

all all of them will be basically under

this particular schema now once the path

is set let's say you know we want to

create a table right so for that you'll

type in create table and then you'll

mention the stable name so let's say I

mentioned students and now each student

will basically have various attributes

right for example let's say I am a

student now I'll have a name I have an

age I have a date of birth and so on so

basically all those values will be a

column so I'll just put it in Brackets

and let's say I mentioned student

ID and int to be data type and let's say

further I again mentioned student name

and then let the data type be where care

255 characters right and then what I'll

do is I'll put a semicolon at the end

once I click over here once I click on

enter you'll clearly see an output that


you know create table now let's go back

over here and then let's just basically

refresh the schemas right so I'll just

refresh the schemas and under the

information table you'll clearly see an

output that you know we have a table

students and then it has columns student

ID and student name so basically that's

how you can create a table basically on

the SQL shell guys now if similarly if

you wish to create a table in the PG

admin what you do is you right click on

the table over here go to create choose

table and then basically you have to

mention the name right so for example

let's say we mentioned the table name to

be teachers and then the owner to be

postgres the schema to be information so

you'll have to basically choose the

schema under which you wish to create

table and then you click on save so if

you click on Save without choosing the

columns then remember that you know this

particular table will have no columns so

if you wish to add columns you can just

add column over here for example let's

say I wish to add column right so I'll

go to plus button over here choose the

name let's say you know teacher ID

let's say data type to be int


right and then you know not null primary

key and all I'll come later on this

session right so I'll click on Save over

here so once I click on Save you'll see

that you know automatically a teacher's

table will be created with a single

column that is teacher ID right so guys

that's how basically you can create

tables in the SQL shell and PG admin now

before I move forward and show you the

various other commands related to ddl

let me cover a concept known as entity

relationship diagram now this particular

concept is important over here because

you know you have to understand how to

create tables and how you have to relate

those tables to the other tables and

basically what will be the column values

for this particular table

so as you can see on my screen guys this

is the example for entity relationship

diagram that I'm going to consider for

this particular session now based on

this particular diagram only I'm going

to basically take forward my session to

show you the different commands also now

entity relationship diagram basically is

a simple diagram through which you can

understand the various relationships


between two different tables or two or

more tables right for example let's say

you know we have this particular entity

relationship diagram right now over here

we have employee Department project and

dependent over here now all the

rectangular boxes on this particular

screen will represent entities now what

I mean by entities is basically that you

know for example let's say I'm a person

right now I have a name now my name my

age my phone number my date of birth my

address all these are basically my

attributes right and I'm as a person can

be uniquely identified with the help of

these particular attributes right so

whatever can be uniquely identified with

the help of attributes is basically

entity right so I am an entity so for

example I am sahity right so my name my

age my date of birth all of this will be

attributes through which anybody can

identify me as sahity right so over here

any employee can be uniquely identified

with the help of an assassin that is

basically a social security number or

you can simply understand as his ID name

now name further can have the first name

the last name and the middle name now

address salary and sex right so


basically all these attributes can

uniquely identify an employee right so

employee over here is an entity and all

these particular attributes are

basically the factors to which you can

identify so when you build relational

database management system what happens

is that employee will become the table

name and all these particular values

that is basically the attribute values

will be the column names right so you'll

have a column name with SSN birth date

first name middle name last name address

salary and sex right so all this

basically will be your column names and

then employee will be your table name

now similar is the case with the other

factors also for example if you take

department now a department can be

uniquely identified with number and name

right so these two will be attributes

and the locations is basically a

multi-valued attribute now when I say

multi-valued attribute what I mean by

that is an attribute can have various

factors right for example let's say

location what will be your address you

can have so much of straight let's say

you know fifth straight fourth Crossroad


and let's say Queens Road right so this

could be basically your location right

now this has various attributes like you

know maybe you can have fifth streets

like the streets can be put into one

value and maybe the Queens Road

basically the main locality can be

another value right so basically it's a

multi-evalued attribute that's what

basically double ellipses mean apart

from that also please remember that even

this particular attribute will be

included into the columns part so you'll

have a department table with the

department number and Department name as

columns now apart from that next let's

look into project the project is again

another entity right so every project

can be again uniquely be identified with

project number and the project name and

the location right now over here the

project number and the project name will

be unique for each and every project so

that is the reason for every entity for

this particular entity these two

attributes are very important over here

because every project can be uniquely

identified with a project number and the

project name and finally coming to

dependent now You Must Be Wondering over


here why does the dependent entity have

two rectangles right that is because you

know it is a weak entity what I mean by

weak entity is basically that you know

the dependent entity is basically

dependent on the employee entity right

for example let's say you know I as an

employee right so I am an employee and

then maybe I'm going for an insurance

right and then I have a health insurance

who in my next nominee let's say is my

sister so what happens over here is

basically that you know this particular

entity is dependent on the employee

entity my details will be basically

taken from the employee entity right so

for example let's say I am an employee

then all my details will be taken from

the employee entity right so that is the

reason basically the dependent entity is

completely dependent on the employed

entity so so that's what you have to

understand over here when I say weak

entity you have to understand that unit

is dependent on any other particular

entity right now over here I hope you

understood what is entities and what is

attributes next if you look into the

diagram we have various other factors


like you know these diamonds and then we

have double lines we have single lines

and so on right so let's look into what

they are so coming to Diamonds over here

when I say diamond what I mean by that

is that is basically the relationship

set so what is relationship set so if

you have to understand this then you can

understand that you know employees are

related to every Department right so if

you take your company any number of

employees like you know more than one

instance of the entity is basically

associated with one instance of the

department right so in simple terms if

you just have to understand it like

let's say you know 10 employees are

working in one particular Department

let's say it department so that's how

basically you can understand this now

coming to the next relationship that is

manages now there's a relationship

between employees and Department also

right so there is a department and then

there is a manager for each and every

Department right so now not all

employees are managers for the

Departments right so it could happen

that you know only one instance of the

employee entity is basically associated


with one instance of the department

entity right so let's say you know we

have the IT department now now the ID

Department can basically have only one

manager the HR department can have only

one manager and so on right so basically

all of them are also employees right so

that is the reason there is a

relationship between employees and

Department over here now coming to the

next relationship that is works on now

it is obvious that the fact that you

know all the employees must be working

on some of the other projects right for

example let's say you know we can have

10 employees working on two projects or

maybe you know the same number of

employees working on some other projects

also right it's never that in Industry

that a single employees working only on

single project and not more than one

project right so in this particular

relationship that is the reason we have

MS to n basically by that what I mean

that you know more than one instance of

the entity employ is basically

associated with more than one instance

of the other entity that is the

Project's entity right so that is


because any number of employees can work

on any number of projects similarly

let's look into the next relationship

that is dependence of what I see in the

relationship of dependence off is

basically one is to n that is because

you know one employee can have any

number of insurance right so you can

have a life insurance and so on so that

is the reason basically you have one is

to end relationship and then you have

the relationship of dependence of

because your dependence entity is

completely dependent on the employee

entity and finally coming to

self-referencing relationship over here

what I mean by self-referencing

relationship is basically that you know

for example let's say you have a boss

right now your boss can handle 10 people

right so basically he's your supervisor

and then he supervises 10 people right

and he himself is also an employee and

all the 10 people are also employees

right so that is where this particular

relationship comes into picture that is

one is to n right so one instance of the

employee where employee is basically a

supervisor can supervise more than one

instance of the other employees right so


basically that's how it happens you

basically have different relationships

like this guys if I have to just

summarize the different relationships

then you have one is to one one is to n

n is to one m is to n right and then you

also have self-referencing relationships

so if you have to talk in technical

terms then you have one-to-one

relationship one to many relationship

many to one relationship and many too

many relationship apart from that we

also have the self-referencing

relationship that I just spoke about now

if You observe the complete entity

relationship diagram over here so I hope

you've understood how entities

attributes and relationship works in the

databases right now let's look into the

double lines over here what do you think

the double nines mean what I mean by

total participation is basically that

you know each entity in the entity set

must at least have one relationship in

the relationship set so basically each

entity in the employee must work in some

or the other department right so that is

the reason we basically have total

participation over here moving on to the


next relationship you can see that you

know it's not necessary that every

employee manages some or the other

person right so that is the reason we

don't have total participation on this

particular side but yes every department

has a boss right so every department has

a manager so that's the reason we have

total participation on this particular

site that is from managers to Department

moving on to the next relationship that

is basically employees to project if you

see every employee has to work on some

of the other project right so that is

the reason we have total participation

on both the sides that you know every

employee basically will be working on

something or the other thing and every

project will have a set of employees

working on it right so that is the

reason we have total participation over

here coming to the next relationship you

can clearly see that you know that the

dependents are basically completely

dependent on employees so it's the total

participation towards from the dependent

side and not from the employee side

because you know it can happen that you

know maybe an employee doesn't have some

insurance or maybe an employee doesn't


have any insurance right so in that

scenario what basically happens is that

you don't have total participation over

here but you have total participation on

this particular site and now finally

coming to this particular relationship

if You observe over here we do not have

any total participation that's because

you know it's not necessary that every

person in the employee table basically

every person in the company should be a

supervisor of somebody right it's not

necessary like that maybe a fresher is

just not a supervisor so in that

scenario basically total participation

will not hold true so that is basically

guys how you can build up an entity

relationship diagram for that scenario

that you have I took a company database

where you know you have various entities

like employees Department dependent

projects and then they are related to

each other in some way or the other and

each of these entities have various

attributes so remember the fact that you

know when you build a relational

database you have entities which will

basically become your tables then you

have attributes so your attributes will


basically become your column names and

then you have relationships so guys this

was all about entity relationship

diagrams you basically have entities

attributes and the relationships right

so I hope you've understood how my ER

diagram looks like now as I was talking

about different kinds of attributes let

me next take you through what are the

different kinds of attributes that you

see so you must have observed right we

had multi-value attributes we had

derived attributes and then we have

complex attributes and composite

attributes so we basically there are

various attributes like you know

Composites simple single multi-valued

stored derived and complex attributes so

let's look into each one of them one by

one so talking about composite and

simple attributes guys if you remember

the entity relationship diagram I showed

you I told you that the name can have

first name last name and middle name the

first name last name middle name Will

basically be my simple attributes and

the name all together will be my complex

attribute so basically if I have to

Define in single terms then a composite

attributes can be divided into smaller


subparts and these subparts can

represent individual basic attributes

with their own meaning for example let's

say we have address right now address

can have street address city state ZIP

and street address can be further

divided into number Street and house

number now city state ZIP number Street

and house number will basically be your

simple attributes so this was about

composite and simple guys now let's move

forward with the next type of attributes

that is single and multi-valued now

attributes having a single value for a

particular entity are known as single

valued attributes and a multi-valued

attribute may have lower and upward

bounds to constraint the number of

values allowed for each individual

entity so you can have a single

attribute and a multi attribute in an

entity and I forgot to tell you one

thing over here every entity is uniquely

identified right so as I told you

employee had SSN that is the social

security number now that is basically

uniquely identified right so that is the

SSN so over here that will be basically

a unique attribute through which the


complete table will be identified next

let's move forward with the next type of

attribute that is stored versus derived

so the attributes which are derived from

the real entities are known as derived

attributes and the stored attributes are

the attributes which are already stored

in the database and from which the value

of another attribute is derived so

basically if you consider age from age

you can derive birth date right and from

birthday you can derive age right so I'm

not saying in the matter of exact

birthday you can like let's say you're

23 years so you can derive the fact you

know at the birthday could be either in

95 96 and if you know the year bond is

95.96 then automatically you can derive

an age that you know the age could be 23

years right so that's how basically you

can understand stored and derived

attribute and finally coming to complex

attributes the attributes that can be

represented by grouping composite

attributes between you know brackets by

separating the components with commas

and by displaying multi-valued

attributes with square brackets are

known as complex attributes right so

basically an address can have phone


number and then the phone can have again

like area code and phone numbers and

then moving forward we can have again

address and maybe add the skin again can

have street address number Street flat

number state ZIP code and so on so

basically this is how you can Define

complex attributes guys so guys that was

about entity relationship diagram so I

hope you have understood how entities

work how attributes work how a table

name can be found and how columns are

formed and how each table can be related

to the other table because this concept

is really important to understand so

that you understand the further Concepts

like you know the keys in databases and

the constraints used now before I wrap

up this entity relationship diagram let

me just shift back to my PG admin and

show you the simple commands of ddl like

you know the create truncate alter and

so on so for example let's say you know

you want to truncate the table right so

when I say truncate what I mean by that

is you basically delete all the data

present in the table but you do not

delete the table itself now since we

haven't added any data into the table


I'll just show you the syntax so that

you can understand so let's say you know

you want to truncate table students

right so for that what you'll do is

you'll type in truncate table and then

you'll mention students

right and then you'll execute right once

you execute you'll see the output that

you know trunky table the query has been

written successfully now since we have

no data is present you cannot see any

particular output but if you had any

data present in the table you would see

that you know all the data would be

removed from the table because let's say

you know you want to rename the table

let's say you want to rename the table

students to let's say in for students

right so to rename the students you

basically have to use two detail

statements that is Alter table and

rename right so for that what you'll do

is you'll type in alter table and then

you'll mention the original name that

students and then you wish to rename

right so you type in rename two and then

you'll mention the new name that is info

students right and then you'll execute

once you execute you'll see that you

know all the tables the query has been


returned successfully so what I'll do is

I'll just refresh this particular schema

and then you'll automatically see that

you know we see an output of info

students right so that means our table

has been renamed now for example let's

say you know we want to add a new column

so for that again you'll use the alt

statement so I'll just type in alter

table and then I'll mention the table

name that is info students and then what

you'll do is you'll mention add and then

you'll mention the column name that is

let's say you know date of birth and

then the data type of it let's say date

right and then you'll end with semicolon

and then you'll execute once you execute

you'll see that you know the query has

been returned successfully so if I just

refresh this part again and you'll see

automatically that you know a new column

has been added onto the table that is

date of birth so this was just for a

single column guys now you can add

multiple columns also so for example

let's say I want to add two more columns

right so what I'll do is I'll just

remove this let's see now I want to add

gender so I'll just mention sex


character and again comma and add let's

say class

okay class is a keyword so I'll mention

standard and then integer right and then

I'll again execute once I execute I'll

again refresh and when I refresh you'll

see that you know automatically my sex

and standards so basically the gender

date of birth and standard have been

added as new columns right so that's how

basically you can add a single column or

you can add multiple columns now you can

also alter the data type of the

particular column for example I want the

data type of the standard column to be

changed to let's say character so for

that what you'll do is you'll basically

mention all the table info students that

is basically the table name and then

what you'll do is you'll mention alter

column and then you'll mention the

column name that is basically standard

and then you'll mention the keyword type

and let's say we mention character and

then I'll execute and now once I execute

and then if I show you the properties of

this particular column you'll

automatically see that you know the data

type is character right so basically

guys that's how you can also alter a


particular table or maybe column maybe

if you want to rename it on now let's

say you know you want to drop this

particular column so for that what you

do is you type in alter table mention

the table name again

and then what you do is you mention the

keyword drop column and then you mention

the column name

right and then you just execute now once

you execute and let's say if I refresh

this you'll clearly see an output that

you know your standard column is gone

right so that's how basically you can

drop a column now similarly if you want

to rename a column it's really simple

you have to write a query like you know

also table the table name and then you

have to mention rename column and then

you mention the column name to the new

column name right for example let's say

I want to change the column name of sex

so what I'll mention is Alter table

input students rename column sex to

gender so that's how you can basically

rename a column also now simply let's

say you know if you want to drop a table

now if you want to drop a table I'll

mention drop table and then I'll mention


the table name right so I'll just click

on execute and then you'll see that you

know automatically your table will be

dropped so if I just refresh this you

see that you know we just have one

particular table that is teachers and

the students table is gone so guys this

is how basically you can work on PG

admin for basically the ddl commands

right what I'm going to do is for this

particular session I'm going to consider

the ER diagram as I mentioned before

right so I'm going to create tables and

manipulate data over those particular

tables only so before I move forward

with this session what I'll do is I'll

explain you the different keys and

constraints used in the database so that

it's more clear to you how you can

create the database in a more structured

Manner and then we'll move forward with

the various manipulation commands until

then what I'll do is I'll just delete

this particular table so I'll right

click here go to delete and click on OK

and then let's say you know we will

delete this particular schema also so

there's no confusion at all

and then what I'll do is I'll close this

shell also so guys remember that you


know I am using PG admin well you can

use the same queries that I mentioned

there on SQL shell also and you'll see

the same output so I hope that's clear

so I'm going to close the SQL shell and

then I'll continue with this session so

now moving forward with this session

let's start with the next topic that is

case in database so there are mainly

five types of keys in database that is

the candidate key the Super Key the

primary key the alternate key and the

foreign key so talking about the

candidate key the candidate key is

basically the minimal set of attributes

which can uniquely identify a tuple so

any minimal set of attributes which can

uniquely identify Tuple is known as a

candidate key so the value of the

candidate key will be unique and

non-null for every Tuple so if you have

to identify a specific Tuple let's say

sahity is 24 let's say date of birth 30

October and so on so on so on then you

need a particular candidate key to

uniquely identify my Tuple right so that

particular can be my employee ID and so

on now let me tell you one thing over

here there can be more than one


candidate key in a relation also so our

candidate key can also be either simple

key or a composite key now coming to

Super Key now super key is basically

again the set of attributes which can

uniquely identify a tuple so any set of

attributes which can uniquely identify

Tuple is known as a Super Key but it's

not the minimal set of attributes the

minimum set of attributes is the

candidate key but as any set of

attributes which can uniquely identify

as known as a Super Key so when you add

zero or more attributes to a candidate

key it becomes a Super K but the vice

versa is not true so a candidate K is

definitely a Super Key guys but the

super key is not a candidate key so

that's what you have to understand now

moving on to primary key the primary key

is also a set of attributes which can be

used to uniquely identify every Tuple

now if you remember the entity

relationship diagram that I was

explaining you I said the employee table

has a special social security number

through which every Tuple will be

identified right so that particular

social security number will be the

primary key to which every Tuple will be


identified and now apart from that there

can be more than one candidate key in a

relation right so out of all the

candidate case is present in the

relation you can choose any one key as

the primary key so if you have around

five candidate keys out of them one can

be definitely your primary key for that

particular relation moving on to the

next type of key that is the alternate

key so the candidate Keys other than

primary keys are basically the alternate

keys so as I was giving you an example

of five candidate keys so if there are

five candidate keys in a relation then

out of which if let's say you know the

first key is chosen as the primary key

then the other four keys will be the

alternate keys and finally moving on to

the foreign key so the foreign key is

basically the key if an attribute can

only take the values which are present

as values of some other attribute so

basically whenever an attribute can only

take the values which are present as

values of some of the attributes then it

will be basically be the foreign key to

the attribute to which it refers so

basically the relation which is


referenced is called reference relation

and the relation which refers to the

reference relation is called the

referencing relation so the referenced

attribute of the referencing attribute

should be a primary key right for

example let's say you know you have

employment department right now you want

to reference Department to employ so

what will happen is you'll basically use

a foreign key to validate this

relationship and then you'll add a

foreign key from Department to employee

I hope that's clear so Guys these were

the various keys that you need to

understand about that is the candidate

key Super Key primary key alternate key

and the foreign key so now that you know

the different keys in database and you

know the ddl commands also let me take

you to the constraints in database so

that we can quickly create the tables

that we discussed in entity relationship

diagram right so the constraints in the

database are as you can see on my screen

that is not null unique check default

and index

so the not null constant basically

ensures that you know a null value

cannot be stored in a column for example


let's say you know you have a student's

table now in the students table you have

a column known as student ID and then

when you're creating the table you

mentioned the not well constraint for

this particular column then whenever

you're inserting the data you have to

remember that you know they cannot be a

null value in this particular column

that is the student ID coming to unique

unique constraint make sure that you

know all the values in the column are

different so in whichever columns that

you want to store unique values you have

to use this constant uni coming to check

this constraint ensures that all the

values in a column satisfy a specific

condition so you have to check let's say

you know we want to store the age of

employees now let's say age has to be

greater than 25 so only the age values

whose value will be greater than 25 will

be stored in the each column if you

mention this particular constraint now

moving on to the next constraint that is

the default constraint this particular

constraint consists of a set of default

values for a column when no value is

specified so whenever let's say you know


you have not inserted any value value

specifically then automatically a

default value will be stored in that

particular cell if you use this

particular constraint and finally coming

to the index constraint this constraint

is used to create and retrieve data for

database very quickly so if you want to

create and retrieve data from database

very quickly then you have to use this

particular constraint that is index so

guys I hope the keys and constraints

concept is clear to you guys so now that

you know we have understood the entity

relationship diagram the consonant and

the keys let me shift back to my PG

admin

and now let's say you know I'll start

creating table so I'll just show you for

one table and then I've already a set of

commands that I've already executed you

know I'm just going to copy paste the

command over here so what I'm going to

do is we have the employee table right

so for that what I'm going to do is I'm

going to mention create schema first so

that you create a schema so I'm just

going to mention create schema let's say

we mentioned schema name to be company

after that what I'm going to do is I'm


going to use this particular schema

right so I'll just mention set search

path to

company

now automatically if I just refresh over

here you'll see that you know there are

two schemas that is company and public

now what I'm going to do is I'm going to

create tables inside this particular

schema so for that what I'll do is I'll

mention create

table let's say we mention employee and

in Brackets what I'll do is I'll mention

all the column names so we had first

name let's say we mentioned text not

null so I'm using a constraint known as

not null right so this particular

constant is used that means that you

know it cannot be a null value in this

particular column similarly let's do for

middle name let's say

care null right so there can be null

values over here now last name let's say

text not null right now I have basically

a social security number right so I'll

put SSN let's say character of let's say

nine characters let's be specific over

here and I'll put not null so this

cannot be null and I also want it to be


the primary key so basically through

this particular number the complete

table will be uniquely identified after

that I'll mention birth date and then

I'll mention the data type to be date

right let's mentioned address

and let's say I mentioned data type to

be text not null this also cannot be

null

right similarly I'll mention six let's

say character null now similarly I'll

mention salary let's say decimal

and then 10 to 2 and this can be null so

we don't know it can happen that you

know we don't know the salaries right

then I'll mention super assassin so this

is basically to identify the

self-referencing relationship if you

remember right and then I'll mention

character of nine characters and this

can be null and then let's say we

mentioned department number Let It Be

int and let's say not null because we

don't want it to be na right now what

I'll do is I'll just execute this

particular query now once I execute this

particular query you'll see that you

know automatically we get an output that

create table so our table is

successfully created so if I refresh


this particular schema and then if I

open tables you clearly see that you

know we have the employee tables now

similarly what I'm going to do is for

all these particular entities I'm going

to create table right so I already have

a dog presence so I'm just going to copy

paste from that so let me just open that

dock right so let me just copy paste

from here so I'm going to copy for

Department Department locations projects

works on and dependent now I'll go back

to my PG admin

and then what I'll do is I'll just paste

over here so what I'm doing is let me

just explain you so I'm creating a table

Department with the column names as

Department name department number MGR

assistant that's because for the

relationship of manager right so if you

remember if I just open a diagram you'll

clearly see that you know employee

managers Department right so you see for

this particular relation and then MGR

start date that is because you know we

have to consider the column present on

the relationship also that is manages

similarly I'm creating Department

locations that is with department number


Department location and primary key as

department number and location together

then I'm creating a table known as

project so the project table will have

project name project number location and

then I've used the primary key to be

project number and then the project name

has to be unique right so I've used the

constraint over there similarly I'm

creating a table known as works on so

for the works on table I have employee

assistant the project number the RS

worked and the primary key to be the

employee number and the project number

together the dependent table will again

have the employee number the dependent

name sex birthday relationship and the

primary key to be employee assistant and

dependent name right so I'll just

execute all these particular queries

so you can see that you know

automatically my query has got

successfully executed so I'll just

refresh this particular table again

so once I refresh this particular schema

you'll see that you know I have six

tables that is the department dependent

dependent locations employee project

works on right

so guys that's how basically you can


create tables and that's how you can use

keys and constraints while creating

tables so guys that was all about the

data definition language commands I hope

you understood how you can use them and

create databases now before I move on to

the next topic that is the data

manipulation commands let me take you

through an interesting topic that is

normalization so what is normalization

so normalization is a technique that

organizes tables in such a way that you

know the redundancy and the dependency

of data is reduced so obviously when

you're storing humongous amount of data

on an industry level there could be

scenarios where you have written and see

so novelization is basically that

technique through which you know you can

remove the redundancy and dependency of

the data so as you can see on my screen

the normalization is basically at four

levels that is one in f2nf 3 NF and bcnf

so let's discuss the same now now before

I move forward with 1nf let me tell you

that you know I'm going to consider this

particular example so the example that

you can see on my screen is basically of

three people you know living in specific


address and they have rented few movies

of a specific category now you

definitely see redundancy in this

particular table right that's because

you know you see Alice Johnson has

rented two movies that is Mission

Impossible and Clash of Titans similarly

to David Allen's address has been

divided and also the movies rented have

also been divided into different

categories right like the Sci-Fi movies

are put into one category and the action

movie isn't put into the next category

and both of them are in two different

tuples this is definitely a return in

data right now how do you think you can

normalize the data well we'll start with

1nf now the rule of 1nf is really simple

guys what the rule says is that you know

each table cell should have a single

value so basically any table that you

have and then you wish to normalize the

data from that particular table you have

to make sure that you know each table

cell has a single value so for example

we had Alice Johnson and David Allen

right so if you remember from the

previous slide we had movies to enter

together right so for Alice Johnson we

had Mission Impossible in Clash of


Titans in the same Tuple and for David

Allen we have the address divided but

also the move is also divided so what

I've done over here is to get the data

into 1nf what I've done is I've divided

all the movies rented into different

tuples so Alice Johnson staying in First

Street house number three has basically

you know specific movies rented that is

Mission Impossible and Clash of Titans

so what I've done is I've divided both

these movies into two different tuples

the same goes for David Allen if you

remember from the previous slide what

happened is that you know in the Third

Street 45 address 1 David Allen had

Interstellar and Edge of Tomorrow

together right so what I've done is I've

divided those two into two different

tuples again and they will add in

seventh annual into the next Double so

this is basically how I've got my table

into 1nf each table cell basically has

only one single value If You observe

over here there's still a problem right

that's because you know our address is

written in for Alice Johnson and for

David Allen our address is redundant and

yes it is divided also it's not all


together so for that what we'll do is

we'll convert this table into 2nf so

basically to normalize such a database

into 2nf to remember the fact that you

know the database should be in 1nf and

should also have a single column primary

key what I mean by that is you know what

I'm going to do is I'm going to divide

the table into two different tables such

that you know for each specific user I'm

going to identify the specific movie

rented for example let's say you know I

give Alice Johnson staying in First

Street house number three ID number one

now I know she rented Mission Impossible

and Clash of Titans right so what I did

was I gave the movies Mission Impossible

in Clash of Titans which are rented by

Alice Johnson the id1 similarly what I

did is for David Allen staying in Third

Street 45 basically for that particular

Tuple I've given the ID to be two we

know that you know he must have rented

Interstellar and Edge of Tomorrow right

so for those particular movies I've

given the ID to V2 and finally for

Mission Impossible Fallout that is

basically rented by David Allen saying

in Seventh Avenue what I've given is

I've given ID number three so that's how


basically I have divided one NF table

into 2nf now if you see over here this

is still a problem right now that's

because you know we still have written

in data with respect to Alice Johnson

and David Allen right because David

Allen's name comes twice as Johnson who

rents two movies comes once but yes the

address is also divided for David Allen

so to normalize this Factor what we'll

do is we'll normalize again so now we'll

normalize the database which is in the

form of 2nf to 3 NF now if you want to

normalize a database from 2nf to 3 NF

the database should be in 2nf and must

not have any transitive functional

dependencies so for that what I'll do is

I'll basically add a salutation ID so

basically I'm going to identify Mr from

one miss from two misses from three and

doctor from 4. so in that way what will

happen is that you know David Allen's

name won't come twice because he'll be

uniquely identified with mister so we'll

type in Mr David Allen so that will only

comes once and then all the movies will

come together so that's how guys

basically you can normalize your

database so we've normalized from one


and if to two NF to NF to 3 NF and

finally comes bcnf now since my example

ends there so I'm not going to normalize

it further but yes if your database is

not yet normalized you can then go

forward and normalize again that is pcnf

so to perform the normalization for the

fourth time what you can do is you have

to normalize right so the condition to

normalize it again is basically that you

know your database must be in 3nf and

maybe you know even after paying in free

NF there would be some anomalies and it

may have more than one candidate now in

such scenarios what will happen is bcnf

will come into the picture and then it

will divide the tables further so that

there would be only one candidate key

present so whenever After 3nf You

observe that you know there's more than

one candidate key and then you'll have

to normalize it again that's where bcnf

comes into picture to divide the table

further so guys this was about

normalization I hope you have understood

how you can normalize your databases now

let's move forward with the next topic

for today's session that is data

manipulation commands now the data

manipulation commands as I said before


are basically the commands which are

basically used to manipulate your

databases so what I'm going to to do is

I'm going to manipulate data present in

the database that I've created over here

that is in the six tables that I've

entered so to initially manipulate data

you need data present in your table so

now to do that what you have to do is

you have to insert data so to insert

data what you'll type in is insert into

and then let me show you for employee

table employee and then you'll mention

values and then you'll have to mention

the values that you wish to enter right

so let's say I wish to enter John as

first name and let's say I'll enter

middle name let it be a character now

similarly I'll enter the next name let's

say Smith that is basically my last name

sorry the comma has to go at the end now

I'll enter SSN right after that what

I'll do is I'll enter birth date so

let's say you know I mentioned

1965.0109 then let's say you know I

mentioned address so let's say I

mentioned 731

Houston

TX and let's say further I mentioned the


gender to be male

and then let's say we mentioned Sally to

be 30 000 and then we mentioned super

SSN let's say

Triple Tree double four four times five

and let's say we mentioned the

department number to be five now once

this is done you can just execute this

particular query so what you can do is

you can just hit on execute and you'll

see that you know automatically the

query has been written successfully that

means the data is filled so if you want

to see the data output what you can do

is you can use the other manipulation

command that is basically Select Staff

from employee so that will basically

show you all the values present in the

employee table so let me just mention

that

and then I'll hit on execute and you'll

see that you know automatically you see

the data present in the table that is

whatever we have mentioned over here now

since guys filling data would be a waste

of time for me to explain for each and

every value I've already put it in my

talk so I'll just copy paste from there

so that we can move faster in the

session right so let me just


copy paste these commands

so if You observe over here what I'm

doing is I am entering data into the

department table the dependent table the

department locations table project

stable works on table and so on so I'm

not entering just one I'm entering quite

a amount of details so what I'll do is

I'll just select all of them together

and then I'll hit on execute once I hit

on execute you'll see that you know the

query has been written successfully that

means that you know automatically our

data has been entered into our tables

right so if you just want to check how

if the data has been entered or not you

can similarly use the same command that

I just showed you that is Select star

from and then you mention the table name

so now let's move forward with the

session now as you remember from The

Entity relationship diagram I said there

were relations between two entities

right so those relations are basically

mapped into picture with the help of

foreign keys that I mentioned before

right so to add foreign Keys what you'll

do is you'll have to alter the table

since the tables are already created so


what you can do is either you alter the

table or or the other way completely

round is basically whenever you're

creating the table you can add foreign

keys so I'm just going to alter the

table since you know my tables are

already created so for that what I'll do

is I'll put an alter table and let's say

you know I add a foreign key for the

manager's relationship so what will

happen is I want to add a foreign key

for the manager's relationship where you

know I'll say the department is managed

by an employee right so what will happen

is department will be our first table

where we'll add a foreign key basically

MGR SSN which references to employee

table because every employee manages a

department

so that's what I'm going to do so I'll

mention all the table and then let's say

we mentioned Department then I'll

mention add foreign key

and then I'll mention the column

attribute which has to match right so

that is MGR SSN that I have created in

the department table and then I'll

mention the references

oh I'm sorry there's a spelling message

over here right and then I'll mention


the table number two that is employee to

SSN so basically you have to add a

foreign key to each of the columns right

so you are basically trying to connect

the MGR SSN column of a department table

to SSN column of the employee table

you'll just execute this and then once

you execute this you'll see that you

know query written successfully that

means there is a foreign key right so

for example let's say if I just refresh

this and then we go to the employee

table and then if we see the properties

and let's say you know we go to

constraints over here and in the primary

key we see that you know it's SSN and in

the foreign key so there's nothing over

here so I had to go to the department

table so let's go to properties because

you know we are adding the foreign key

from there right so I go to foreign key

you see that you know mgrs is in foreign

key basically MGR SSN is connected to

SSN so you clearly see that you know

that's how you can add foreign key now

what I'm going to do is I'm going to add

foreign keys for other tables also so

that you know we can move forward again

let me just directly add it from here


right so as you can see on my screen

I've mentioned a foreign key between

employee SSN and employee super

assistant so that was basically for our

self-referencing relationship then I

mentioned a foreign key between

department number and the department

basically who works on which department

right so for that particular

relationship after that I've mentioned a

foreign key for Department locations and

the department so basically which

department is present in which location

after that I've mentioned the foreign

key between project and Department

basically which department is looking

into which project and then I've

mentioned a foreign key between works on

table and employee table to understand

which employee is working on which

project or which department and finally

on the dependent and the employee table

to make sure the dependency relationship

is taken into account right so what I'll

do is I'll just execute all these

particular foreign keys so I'll hit on

execute you'll see that you know

automatically the query has been

executed right so guys that's how

basically you can add foreign keys to


all your tables you know if you just

refresh over here and then if you check

all the tables you'll see that you know

there's some of the other foreign key

present for each and every table that is

for each and every relation now let's

move forward now for example let's say

you know I want to see all the details

from the works on table right

now let's say you know I want to delete

records with the project number let's

say 30. let's try deleting right so if I

try deleting let me just write it over

here delete from you have to delete from

the project table and then I'm saying

the project number I've considered 30

right so I'll just type in 30 and let's

see what happens when we execute this

okay I'm sorry

yes now when you execute this particular

statement what do you say you see an

error that you know update or delete on

the table project while it's foreign key

constraint because we have a foreign key

with respect to work sound right so

because we've just mentioned over here

that you know we'll have a foreign key

with works on and project number so now

that's the reason we get this error now


to resolve this error basically I'm

talking about the concept where you want

to delete the records where foreign keys

are present right so what you'll do is

you'll initially delete the record from

the works on table and then you'll go

forward and delete the records from the

project table so you directly won't come

over here what you'll do is you'll

initially delete from works on table so

let's say p number is 30 right

so I'll delete the record from the works

on table over here you'll automatically

see that you know query returns

successfully and now if we try deleting

data from Project table what you'll

clearly see that you know query is

written successfully that means there

was no violating error right so what

happens is whenever you have a foreign

key from a table to P table remember

that you know if you want to delete

anything from the B table you have to

first delete it from the a table and

then you can go forward and delete it

from the B table right so guys that was

about the insert statement the alter

statement and about foreign Keys now in

this session what I'm going to do is I'm

not going to talk about any theory part


like what's gonna happen and then how

you can use what I'm going to do is I'm

going to directly jump on the query so

that you can understand how you can

write queries and how you can manipulate

data so let's get started so now let's

say you know we want to update the

salary of employees so for example let's

say I'll just see which employee salary

has to be updated so I'll just type on

select star from employee so that I can

see the details

so I'll just execute this so when I

execute this you'll see that you know I

have all the details right now let's say

you know I want to update the salary of

a person let's say employee whose SSN is

let's say triple line double eight four

times seven now let's say the salary is

around 25 000 right now I want to update

it to 27 000. what can I do is basically

I have to use the update statement so to

use the update statement what I can

simply do is let me just press on enter

so that the screen is clear for you guys

I could just type in update and then you

have to mention the table name so that

will be employee and then you'll mention

set column name and then what you'll do


is you'll mention the new value that you

want that is let's say 27 000 and then

let's say where SSN that is basically

through which you can uniquely identify

every Tuple right so where SSN is equal

to what was the SSN it was Triple line

double eight four times seven right so

I'll just type in

triple nine double eight four times

seven and then what I'll do is I'll just

end with a semicolon once I execute this

you see an output that you know query

returns successfully right so now let me

just go back over here and choose Select

Staff from employee and now if we go

back to this particular table you can

clearly see that you know the employee

who had an SSN about triple nine double

eight four times seven has now a salary

of 27 000. so guys that's how you can

update the values so guys that was about

the update statement now let's say you

want to delete a tuple's data you know

let's say more than one condition so

what you can do is you can just use the

delete statement

okay delete from and then let's say we

want to delete it from works on table

right so I'll just type in works on and

then let's say where employee SSN


because our works on table has employee

ssns column right so over here if you

can see we have essn and let's say you

know we use the same employees and let's

say triple nine double eight and four

times seven and we also have project

number details right so here I'll choose

project number let's say

right so that is basically the data I

had mentioned so I'll just execute this

particular query and you see that it

automatically is executed right so now

if I just change this from employee to

works on and then if I execute this

particular query you can clearly see

that you know we have no employee with

employee ID of triple line double eight

four times seven and working on Project

number 10's data present in the works on

table so guys that was about how you can

delete update insert and alter now let's

move forward with one of the most

important queries that is the select

query now the select query is basically

you considered as one of the most

important queries because you know this

is the query through which you can

retrieve the data so as you can see over

here I was using select query again and


again because you know I wanted to

retrieve the data that I have in my

database so that's where basically the

select query comes into picture now when

I had select star from works on that

means all the data was shown for example

let's say I just want the first name

last name and the address from the

employee table and let's say you know we

are specific to department number five

so what I can do is I can just type in

select first name last name

address

and I'll mention from employee and let's

say we mentioned department number is

equal to 5.

so I'll execute this particular query

so when I execute this particular query

you can see that you know John Franklin

ramation Joyce so basically the first

name last name and address have come

into picture right so uh that's how guys

you can use a select query now this was

quite a simple one right now let's look

into something more complicated for

example let's say you know you want to

retrieve data for every project located

in belari and then you want the project

number the controlling department number

and the department manager's last name


address and birthday so over here if You

observe what all I have taken into

account the project number the

department number the department

managers the last name address and birth

date so if You observe over here

basically what's happening is there are

three tables coming into picture right

that's basically the project table the

department table and the employee table

so let's look into how we can write the

query for this so what all did I mention

I mentioned the project number the

department number last name address and

birth date so what I'll do is I'll

mention select and then I'll mention all

these factors that is Project number the

num right and then I'll mention L name

that is basically my last name and then

I'll mention address say we mentioned

birth date right and then I mentioned

from uh what are the tables that I had

considered that is the project

department and the employee right so

I'll mention project

Department employee

where the num is equal to D number so

basically the department number from the

project table has to match the


department number from the Department

table also so that's basically you use

an operator known as and and then you

mention MGR SSN that is basically who

manages the project has to match with

the employee code that is right SSN

apart from that we also have to mention

that you know our project location is so

we'll mention and P location is equal to

in codes will mention

pillar right so if I just execute this

particular query

you'll see an output that you know there

are no tuples which satisfy this

particular condition right so what I'm

going to do is let's say we change

bellary to let's say house still right

now let's execute again now if I execute

on Houston you can see that you know

we've got the project number the D num

the last name the address and the birth

date of basically all those employees

who work on the project basically

located in Houston so that's how guys

you can basically integrate two to three

tables together and use the select

statement to further play around with it

now if you remember I was talking about

the self-referencing relationship where

you know we have employee related to


himself right that was basically how a

supervisor can have a supervisor so for

example let's say you know for each

employee we want to retrieve the first

name and the last name and also the

first name and the last name of the

supervisor then what we can do is we can

use the select statement again right

and then I'll mention e dot f name and E

dot L name so this is basically to

identify every employee right so that is

basically the Super Y Z now if you want

to identify the supervisor what I'm

going to do is I'll mention s dot f name

and s dot L name and then I'll mention

from and then I'll mention employee

sorry let me put it in small so that

it's clear to you from employee as e

right so for every employee that is

basically for every Super Y Z I'm

identifying employee as e and similarly

for supervisor I'm going to identify as

s right so I'll mention employee as s

where e Dot

super SSN is equal to s dot SSM now if I

just execute this particular query you

see an output that you know we have the

first name and the last names of the

supervises and the supervisors so that's


how basically you can play around with

the names of the columns and the tables

also guys so I hope you've understood

this particular query now moving forward

you might have heard about the term

distinct so when I say distinct what I

mean is I want to find out all the

unique values right so to find out

unique values you have to use the term

distinct let's say we want to find out

the distinct salary values for all the

employees right so now what I can do is

I can just mention select distinct and

then I choose the column salary from the

employee table

and then I click on execute so you'll

automatically see that you know we see

all the distinctive salary values

present so whenever you want to find out

any unique values or let's say distinct

values this is basically the keyword

that you have to use that is distinct so

guys that was about the distinct query

now let's move forward and understand

the cross product now cross product is

something like you know when you have a

into B right so basically you have a and

then you want to find out all the

combinations of a with B that's when you

use cross product for example let's say


you know you want to find out all the

assessments basically of all the

assistance of the employee and then you

want to find out all the combinations of

employee assistance with the Department

name so let's do that so what we can

simply do is to perform cross product

you can mention select

SSN and the name from when mentioned

employee and Department

so if I just execute this particular

query you'll see that you know we get

all the combinations of Assassins with

Department name so let me just drag a

little bit

right so as you can see we have for each

SSN we have various departments like you

can see we have the research Department

the admin Department the headquarters

department and so on so that's how

basically you can perform cross product

now let's say you know if you want to

take this query further so let's say you

know we want to find out all the

employees who work in the department

let's say Administration so what we can

simply do is we'll type in select

star and then I'll mention from employee

Department
and then I'll mention aware condition

which says the name

is equal to

add ministration

and the number is equal to

D number from the Department table so if

you have any queries with how am I

mentioning the column names you can

always refer to the tables that you have

and then you can go back to the tables

and check for the column names for

example let's say I go to the department

then you can see that you know I have

the department number over here so I'll

just execute this particular query now

and once I execute this particular query

you see that you know we get all the

details of all the employees who work in

the department administration right so

if I just extend this you clearly see

the output right so guys that's how

basically you can play around with the

select statements now before I move

forward with the further data

manipulation language commands let's

look into the next topic that is

operators now there are various kinds of

operators present in the SQL commands

that is arithmetic operators The bitwise

Operators the comparison operators and


the compound operators so the arithmetic

operators are basically used to perform

the arithmetic operations as you can see

on my screens plus minus into divide and

mod bitwise has bitwise and orange or

comparison has greater than less than

greater than equal to less than equal to

2 and then not equal to and so on and

the compound operators have you know

increment like you know a is equal to a

plus 1 can be written as a plus equal to

so that's how basically you can use

operators guys well I'm not going to

explore more about operators because

that's a really simple topic that you

can explore about right so I've just

given you a basic understanding of the

top operators well don't worry we'll be

look forward into these particular

operators later on in the session so

let's get started with our next topic

for today's session that is nested

queries so nested queries are SQL

queries which have an outer query and an

inner query so the sub query is a query

nested within another query such as

select insert update or delete so for

example if you see the screen that is

basically the outer query and the inner


query so I have an Iota query which says

select last name first name from

employees let's say you know where

address in and then we choose you know

we mentioned an inner query which says

select address code from Office where

country is India right so based so if

the condition matches then automatically

this query will be executed and then

we'll get the output so this was about

nested queries guys so now what I'll do

is I'll now explain you a little bit

more Concepts and then I shift back to

my PG admin to show you how you can

write nested queries and Implement

various other queries so on that note

next let's look into what are set

operations now all of you might be

knowing what are set operations right

it's basically Union intersect and minus

for example let's say you know you have

set a and set B now if you perform the

union operation between set a and set B

what you'll get is you'll basically get

all the data present in both set a and

set B coming to the intersect option

basically if you have set a and set B

and then if you perform the intersect

operation between both these sets what

you'll get is only those rows which are


common in both the queries and finally

coming to minus status you can basically

mention minus or except right so for

example let's say you have set in and

set B and then you mentioned set a minus

set B you basically keep all the rows

from the left query which are not

included in the right query now the vice

versa is also true for example if you do

set B minus set a then you keep all the

queries from the right query which are

not included in the left query so that's

how basically you can perform set

operations guys so in the matter of

database Management Systems if you have

to understand then you can understand

set a and set b as left query and write

query so as you can see from the

pictorial representation over here if

you do Union then you get all the rows

from both the queries if you do

intersect then you get only those rows

which are common in both the queries and

then if you perform the minus operation

or the accept operation you get only the

rows from the left query which are not

included in the right query or maybe

only those rows which are included in

the right query but maybe not included


in the left query right so guys that was

about set operations so now let's move

forward and let's look into special

operators so when I say special

operators there's nothing much big deal

about it they're just few operators

which are special like you know between

is null in exists all in any so these

are various operators this is not

something that you need to learn in

depth but as you write queries you

should have an idea about all these

operators So when you say between

operator what I mean by between operator

is basically that we want to mention a

condition between A and B so whatever

values which satisfy the condition

between a and B all those values rows

will be printed similarly is null so the

is null operator is basically used to

test for the null values now since you

know it is not possible to test the null

values with comparison operators like

greater than or less than we can simply

use is null and is not null operators

instead so what you can simply do is you

can just find out where if address is

null or maybe if the date of birth is

null and so on coming to like operator

the like operate is basically used to


get the date of all those values which

either start with a character specific

character that you mentioned or maybe

end with a specific character that you

mentioned or it could also happen that

you know you have few spaces and then

you mention a specific character you

also want all those rows coming to in

operator this is basically a shorthand

operator for multiple all conditions

which allows you to specify multiple

values in where Clause so this is

basically used when you want to use

nested queries right coming to exist

operator exist operators basically used

to test if a record exists or not if it

exists it's fine if it doesn't exist

then it returns an output that you know

the query not found and finally coming

to the all operator the all operators

used with a where or a having clause and

it turns true if all the sub query

values meet the condition so this was

about all operator coming to any

operator the any operator is also used

with the where and the having Clauses

and returns true if any of the sub query

values meet the condition apart from

that over here I also want to tell you


about the order by Group by and be

having process so the order by is

basically to order the data that you

want in a specific format let's say you

know sneak other descending order and so

on the group is basically you want to

group the data According to some

specific column and so on right and

having is basically where you're

checking let's say you know having

salary greater than 25 000. so only

those steppers will be written whose

salary is greater than 25 000. so guys

that was about group by order by and

having Clauses also now let's move

forward with the next one that is

aggregate functions so aggregate

functions is also one of the most simple

topics so aggregate functions is mainly

used with the nested queries that is

basically the min max the count average

and sum so the Min function is basically

used to return the smallest value of the

selected column in a table the max

function is basically used to return the

largest value of the selected column in

a table the account function is

basically used to count the number of

rows that match a specified criteria the

average function Returns the average


value of a numeric column that you

choose and the sum function Returns the

total sum of a numeric column that you

choose now that was about aggregate

functions guys so don't worry I'm just

brushing you with the topics basically

the concepts I'm going to show you how

you can use all these Concepts based on

the queries that I'll execute on the PG

admin in a while now but before that let

me just take you through the limit

offset and fetch values

so the limit is basically used to limit

the number of data that you want to get

now we want only the data of the first

five rows so what we'll do is we'll

basically mention Select Staff from

employee limit five what will happen is

automatically we'll see the first python

coming to offset offset is used to

basically select a specific number of

rows after the limit right for example

let's say after the fifth row we want

three rows right so what we'll do is

we'll use the offset statement to

basically mention that you know after

the fifth row we want three rows right

so basically only after the fifth Tuple

is read automatically six seven eight


will be printed out as an output coming

to fetch fetch is also one of the ways

to limiting the query results right so

whenever you want to fetch let's say

first five rows only or maybe let's say

10 rows only then you can use the fetch

statement so I'm going to show you how

that's done let me just shift back to my

PG admin and now what I'll do is I'll

start with the first topic that I had

discussed over here that is nested

queries so let's write some interesting

nested queries so that you get a

hands-on experience and how you can

integrate into a complex queries right

so for example let's say you know we

want to make a list of all the project

numbers for projects that involve an

employee whose last name is Smith either

as a worker or as a manager of the

department that controls the project so

our main question is basically to list

the project numbers for projects that

involve the employee Smith now that

particular employee can either be the

manager or can also be the worker of

that particular department and controls

the project so to do that what I'll do

is I'll have to write a nested query so

the reason for nested query is simple


that is because you know we have to

first find out all the projects where

you know Smith is working as an employee

later on we'll find out the projects

where Smith is working as a manager

right so let's start with Smith working

as a manager so for that what we'll do

is we'll type in select this thing

because we want unique records and let's

say p number that is basically the

project number from

project and then we also want the

department

because we're going to use a department

table and then we mention employee

because we're going to use the last name

where we'll mention the num is equal to

the number

and MGR SSN is equal to SSN

also my last name should be Smith right

so I'll mention last name is equal to

right so let me just remove this

put in a wheel

and let me put a bracket now let me tell

you one thing over here this is not the

end to the query because we also want to

find out all the project numbers where

employee Smith is working as a worker

right so for that what we'll do is we'll


use the set operation Union right so

because this makes sense right we want

all the values from set a and then we

also want all the values from set B so

that is the reason we'll use the union

operation and then we'll mention

select distinct p number

from Project

works on

employee where

p number is equal to p number that is

basically the project number from the

project table and the works on table

and employ SSN from the workzone table

to SSN from the employee table apart

from that we also have to mention that

last name should be Smith right so we'll

mention and L name is equal to

Smith

right so I'll end it with a semicolon

and let me just remove this type over

here

and then let's execute this particular

query

all right it says Department oh yes

there's a spelling mistake over here

right and now

let's execute again so once I execute

you see that you know I get the project

number one two that means that you know


the person with the last name Smith

works as a manager or maybe works as a

worker in these two projects that is

Project number one and two so guys this

was a nested query with the Union

operation now let's say you know you

don't want to use any set operations and

let's say you just want to write a

simple query let's take an example for

that now let's say you know we want to

retrieve the name of employees who have

no dependents right so we had a

relationship with says employees have

dependence right so let's say you know

we want the name of employees who have

no dependents so for that what you can

do is you can just type in the query

select

first name let's say we take first name

and let's say we take last name

from employee

where

will mention not I'm sorry I have to

correct the spelling of where we are

we'll mention not

exists and then I'll again mention a sub

query which says select star

from dependent

where we have to match the SSN right so


SSN is equal to essn right so I'll just

execute this particular query and then

once we execute this particular query

you'll see an output of all those

employees who have no dependents so

that's how guys basically you can use

this operator of not exist what I've

done is I've basically taken the

operator of x's so if it exists what

will happen is that initially the sub

query will be executed with say select

star from dependent where SSN is equal

to Essence so this query will generate

all those results which have the

dependence right so basically all those

employees who have dependence that

particular result will be generated over

here then I put a not condition before

that so when I put a not condition the

output gets reversed and automatically I

got that output printed so if you just

mention exists over here and then if you

remove not and then again if you just

execute this particular statement you'll

see a different output so this is

basically the output of all the

employees who have dependents so now

let's take this query further and let's

say we want to find out the names of

those managers who have at least one


dependent so what I'll mention over here

is I'll mention select first name last

name from employee well exist and then

I'll change this condition select star

from dependent where SSN is equal to

essn and also I have to take this

condition further which says and exists

and then I again have a nested sub query

which says select

star from Department because we are

considering manager right where

SSN is equal to MGR SSN

so I'll just close this bracket over

here and then I'll remove one bracket at

the end and let me put an enter so

that's clear to you so what I'm

basically doing is I'm basically listing

the name of managers who have at least

one dependent so for that what I've done

is I've used an auto query which has a

sub query and underneath that I again

have another sub query so for that what

I'm using is select first name last name

from employee where exists and then

again I have a sub query which says

Select Staff independent where you know

SSN is equal to ESL this will basically

give the output of all the employees who

have dependents now after that we also


have to match from Select Staff from

department where SSN is equal to MGR

resistance which is basically the name

of managers that we want after that

we're taking dependence into account and

then we are returning the first name and

the last name so if you see the output

we get Franklin and Jennifer right so

Frank sin and Jennifer are those

managers who at least have one dependent

so guys that was about exist and not

exist how you can use and all

let's move a little bit further and as I

was talking about operators like the

special operators let's look into few

queries related to that so let me just

press one enter over here so that I can

make the screen clear for you now let's

say over here we want to retrieve all

the employees whose addresses in Houston

Texas

so it's really simple what I can do is I

can just generate select SSN and first

name

from employee

where

address like and then in quotes I'll

mention percentage

Houston

and percentage
sorry and then what I'll do is I'll end

with a semicolon over here so basically

I'm generating the SSN and the first

name of all the employees whose address

is in the house in Texas right so let me

just execute that so once I execute you

see an error that you know where address

okay so that is basically because our

spelling is incorrect over here

so let me just execute again so once I

execute you see SSN and first name of

all those employees whose address is in

Houston Texas right so if you want to

check this information you can go back

to our employee table and then you can

check the information for sure so that's

basically how you can use the like

operator now let's say you know we want

to find out all those employees whose

first name as let's say five characters

so if you want to mention five

characters how will you do that any five

characters not necessarily that you know

it has to start with f or s or a or any

other character it can be any character

that you wish to right so in that

scenario let's just generate select

first name and let's say I again

generate assassin from employee where


first name like

okay there's a typo over here

and then I'll mention five characters

right and then I'll end with a semicolon

so let's just execute this particular

query and you'll see that you know it's

just Joyce Ahmed and James who have

first name with five characters so all

the other employees who have first name

with any other number of characters are

not taken into account so that's how

basically you can use the like operator

guys now let's say you know you want to

use the between operator for example

let's say that we want to find out all

those employees whose salary lies

between let's say 30 000 to 45 000. so

for that I'll type in the statement

select

star from

employee

where

and then you mentioned the nested query

salary between

and then you mentioned 30 000

right and forty thousand

right and so let me just execute this

particular query all right once I

execute this particular query you get

the information of all those employees


who sell the likes between thirty

thousand to forty thousand so guys

that's how you can use the between

operator now as I'm talking about

operators let me just show you a simple

functionality of the arithmetic operator

Also let's say you know we want to show

the resulting salaries of each and every

employee working on the product y

project and let's say you know it's

given a 20 raise so to do that what you

can do is you can write a query let's

say select e dot f name so if you

remember I used a similar query

previously also and then I choose e dot

L name and then I mention

1.2 right into that is basically my

arithmetic operator that I'm using and

I'm choosing e dot salary as as let's

say increased salary

from I am choosing employee table

because salary is an employee table and

then since I'm using e dot f name I'll

mention employee as e and then works on

W and project

as p and further what I'll do is I'll

mention where

employee.ssn is equal to is equal to the

works.ssn right so whatever employee is


working on product y right so that's

what we want to find out over here so he

has to First satisfy the condition of

the Assassins have to match apart from

that we'll consider and all right this

has to be essn right and then I'll

mention work dot p number is equal to

P Dot p number

and P dot P name is equal to

product y

so let me just end this particular query

over here and now execute it once I

execute you see that you know we get the

first name and the last name and the

increased salaries of all those

employees who have worked on product Y

and their salary is increased by 20 so

that's how guys basically you can use

the as operator and also arithmetic

operators together now as I was talking

about one more operator that is is done

so if I have to talk about Isner let's

say you know we want to find out all

those employees who do not have any

supervisor so then directly you will use

is null operator so in that scenarios

what you'll basically do is you'll write

a query like you know select let's say

star

from
employee where super SSN is null I am

basically using this is null operator to

find out all those employees who do not

have any supervisors so I'll just

execute this and then once I execute

this you get the details of that

particular employee who doesn't have a

supervisor so guys that was about

operators and all I won't go into each

and every operator now I'm leaving the

rest to you so that you practice so next

let's look into how you can use

aggregate functions in SQL so to use

aggregate functions what you can simply

do is you basically have to use the

functions as some Maximum average and

count right for example let's say you

know we want to find out the sum the max

the Min and the average salary from

employee let's say so let's say you know

I want to find out the sum min max of

salary from employee right so I'll just

mention select sum salary

min

salary

Max

salary

from employee right

so when I mention that you'll see that


you know the sum is so much the minimum

and the maximum is so much right that

was about some min max now let's say you

know I want to count the salary so what

I'll do is I'll basically change this

particular function to count right and

then I'll say count distinct salary

because I'm going to count the unique

ones right and then I'll mention from

employee right so I'll just remove this

particular section right and then if I

just execute this you'll see an output

of 7 right so basically we have seven

distinct salaries so that was about

aggregate functions guys now next let's

look into order by Group by and having

Clauses so as I mentioned before the

order by is basically used to get the

output either in the ascending format or

the descending format the grouper is

basically used to group the data that

you want by a specific column and having

it basically used to check a condition

let's say we want to write a query to

retrieve a list of employees and the

projects they're working on ordered by

the department and within each

department they have to be ordered

alphabetically by the last name and then

the first name so initially they have to


be ordered by department and then under

each department also they have to be

further ordered by the last name and the

first name so to do that what you can do

is you can just mention

select and then you mention T dot T name

right and then you mention e dot L name

we also want the first name right so

we'll mention e dot f name and then P

dot P name from Department this is a

typo and then we also want employee we

also want works on right now over here

we have to mention as W over here

as e over here as D over here and then I

forgot to mention the project so project

as p and then you have to mention the

condition which says where D dot the

number is equal to e dot T number and

employee dot SSN is equal to works on

dot SSN and workstorm.p number is equal

to P dot p number

and then it is order by D dot T name and

then I mentioned e dot L name

add e dot f name

right and then if I just end this

particular query let's execute this

particular query you see an error that

you know w dot SSN not found because

this has to be essn right so I'll have


to mention essn over here and then let's

execute this query again

it's a typewriter again which is p dot p

number

right now let's execute again and you

see an output of D name L name f name

and project name so initially if you see

the D name is ordered by alphabetically

that is in the ascending order from a to

R and then under Administration Wallace

and Jennifer have come similarly

headquarters have Borg and James

research has a lot of values but

underneath that also we have ordered

them according to ascending order by

which I mean that you know it is ordered

alphabetically by last name and then the

first name so that's how basically guys

you can use the order by now this was a

little bit complicated one if I just

have to explain you with simple one what

you can do is you can consider the query

of let's say you know we want to find

out the salary of all the employees in a

descending order so what we do is we

just type in select star from employee

order by and then we mentioned salary

descending order

right now if I just execute this

particular query you'll see that you


know we get all the details of all the

employees in the salaries of the

descending orders so in the case of

descending if you mentioned ascending

then you'll get an output of all the

details of all the employees in an

ascending order of based on the salaries

so guys that was about the order by

class now let's move forward with the

group by Clause now let's say you know

we want to find out for each department

we want to retrieve the department

number and the number of employees in

the department right so now to retrieve

the number of employees you know the

aggregate function we have to use the

count function and then we want to group

it by the department number right

because we have to do it for each

department right the question says for

each department we want to retrieve the

department number and the number of

employees so to do that what I'll simply

do is I'll mention a select query

department number and then account

function of all the employees and then

I'll mention

from employee right so let me just press

on enter so that the keyboard doesn't


move and then I mentioned group

by D number right because we want to

find it for each department we're using

this so for each department we have a

count like you know in the department

number five the number of employees

working up for in a department number

four the number of employees working at

four are three and in the department one

the number of employees working are one

all right so that was about the group by

Clause guys I hope that was simple to

understand now let's look into the

having Clause so having as I mentioned

before is basically used to specify a

specific condition so let's say you know

having count less than two greater than

two having salary greater than 25 000 or

maybe less than 30 000 and so on now

let's say you know we have a scenario

where we want to retrieve the data for

each project on which let's say more

than three employees work we want to

retrieve the project number and the

number of employees who work on the

project our main condition is that you

know for each project where the employee

count is more than three right so for

that what I'm going to do is I'm going

to mention the condition select pin


number that is because of the project

number and then let's say I want to

count the employees right so I'll

mention count star

from Project

works on

where p number is equal to p number and

then I group Pi for each project right

so when you Group by you basically have

to group by project number and then I

mentioned the condition have a count

greater than I forgot to mention the

aster condition over here

three

so basically I'm mentioning the

condition that you know we want to

retrieve the project number and the

count of employees who are working on

the project where the project number

from the project table matches the

project number from the works on table

and then it is grouped by project number

where the count is more than three now

if I execute this particular query you

see that you know there's no data

returned right so that may be because

you know the condition is not satisfied

by any of the data that we have so let's

say you know we want to do it too so I'm


just mentioning the condition to be 2

and I click on enter and then you see

that you know we get the project number

two where you see the count is free and

then the project number 20 where you see

the count is three so initially when I

mentioned the condition having count

greater than three the output did not

come because there was no such data

present so that's the reason there was

nothing returned but when we change the

condition you see that you know we get

an output of two project numbers

so guys that's how basically you can use

the group by Clause the order by clause

and the having Clause next as I was

talking about the limit offset and fetch

let me just quickly cover that

particular part so that we can go back

and learn about SQL joins now talking

about a limit as I told you if you want

to limit the data that you want to fetch

right so basically let's say you know we

want to just fetch five rows right what

you can simply do is you can just type

in select

star from let's say works on

and then we limit

five

right and now if I execute this


particular query you'll see an output

that you know only five rows of data

will be printed out so that's because

you know we're limiting the data that

has to be written now let's say you know

we want to select three rows from let's

say works on table after the fifth row

so we want the next three rows to be

printed after the fifth row so for that

you have to use the offset statement so

what you'll do is you'll mention select

start from works on and then what you'll

do is instead of limit over here you'll

mention offset 5 and then over here

you'll mention limit three

so after the fifth row you want three

rows to be printed so that is the reason

you'll mention offset pipe and limit

three so let me just execute this

particular query so if I execute this

particular query you'll see that you

know I've got the output of 6 7th and

eighth row so basically guys that's how

you can use the offset statement now

let's say you know if you want to use

the fetch statement so as I mentioned

before the FED statement is also used to

fetch the records so let's say you know

I want to fetch the first eight rows so


what I'll do is I'll mention select

start from works on and then mention

offset 5 and then I'll mention first

eight rows only

so after the fifth row what I'll mention

is I'll mention select star from works

on and then I'll mentioned batch

first eight rows only right so if I just

execute this particular statement

you'll see the first eight rows so over

here you can clearly see the output that

you know when we used limit Phi you saw

the first five rows and then when we

used offset 5 and then limit free we saw

the next three rows and now if you're

using the fetch command where we say

fetch first eight rows only you'll see

that you know we fetch all the eight

rows right so that's how guys basically

you can use the limit offset and the

fetch commands so that was about till

now now let's go back to our ppdn next

let's look into joins in SQL so all of

you might be knowing what are joints

right the joints in SQL are commands

which are basically used to combine rows

from two or more tables based on a

related column between those two tables

so they are predominantly used when a

user is trying to extract data from the


tables which have one to many

relationships or many to many

relationships between them so if you

just have to understand joints in a

simple language then joins in SQL are

basic commands which are used to combine

rows from two or more tables based on a

relative column between those two tables

so basically there are four types of

joints present that is the inner join

the left joined the right join and the

full joint so as you can see on my

screen the inner join is the joint which

is used to return the records which have

matching values in both the tables so

whenever you have matching values in

both the tables you use inner joint

coming to the left join the left join

returns records from the left table and

also those records would satisfy the

condition from the right table the right

join returns records from the right

table and also those records will

satisfy the condition from the left

table and finally coming to full joint

the full joint returns all those records

which either have a matching value in

the left table or on the right table so

Guys these were the mainly four types of


joints that is the inner join the full

the left and the right join now let me

just quickly take you back to PG admin

and then let's apply a few joints on the

tables that we have for example let's

say you know we want to apply left join

right as I've told you before the left

join is basically going to return all

those records from the left table and

also all those records matching the

condition from the right table what I'll

do is and mention select let's say SSN I

am going to mention first name and then

I mentioned dependent

dot dependent name and then I'll mention

dependent dot relationship which is a

column of the dependent table and then

I'll mention from employee left join and

then I'll mention the table one that is

basically dependent

on

employee dot SSN is equal to

dependent dot essn so when I execute

this particular query you see an error

that you know the table is not found

because we have an error with the column

name so let's just check the column name

okay it's underscore so I'll mention

underscore over here

so when you see the output you can


clearly see that you know we've got all

the records from the left table that is

the dependent table and then all the

records which also match with the

condition from the right table so that's

how guys you can apply left join now

similarly you can apply right join also

so for the same condition let's apply

the right join and let's see the

difference in the outputs right so what

I'll do is I'll just scroll again and

then I'll just change it to right join

and now I'll execute again so let me

just execute this particular query and

once I execute this particular query

you'll see a difference right so that's

basically how you can play around with

joints guys this was about left and

right now before I conclude the Joints

Part let me also talk about the inner

join and the full joint so the inner

join is basically where you have

matching values in both tables right so

let's say you know we select SSN and

first name and let's say you know we

remove this particular section and then

we mentioned from employee

I'll mention in a joint dependent on

employed at SSN is equal to dependence


so we'll get all those records which

have matching values in both the tables

right I'll execute this particular query

and you'll see the output right so these

are basically all those values which

have a matching values in both the table

a and table B and finally let's say you

know if I want to specify the full joint

which basically will give me the output

of all those records which either have a

matching value in the left table or on

the right table what I can do is I can

simply mention full join over here

and then I execute this and then you'll

see an output like this right so

basically you'll see that you know these

are all the tuples which have either a

matching value in the left table or on

the right table so guys that was about

joints next in this session let's move

forward and take a look at the views so

views are really simple guys as the name

suggests views in SQL is a single table

which is derived basically from the

other tables so for instance if you

consider the example on my screen I have

two tables right now for example let's

say I want to create a new view which

will basically have few columns who rows

from a specific table and few columns or


rows from the other table right so that

is basically my view so now views are

used in Industries to basically

collaborate with the data of many tables

so that the company can understand how

to go about the next action step they

should take while taking any specific

decision so without wasting very any

further time let's take a look at how we

can create a view

so to create a view it's really simple

either you can use the query tool or

what you can do is you can just go to

the view option right click over here

choose create and choose View since I'm

writing queries for all of them I'll

show you by writing queries itself else

you can use this option also so talk

about views so to create a view it's

really simple as you create a table you

can similarly create a view like you

know create

View and then you mentioned view name

let's say we're going to create a view

for the works on table so I'll mention

works on one and then what I'll do is

I'll mention the condition so if you

stop over here this will simply create a

view and this will not store any


particular data that you want but if you

start mentioning the condition then it

will have all the data according to the

condition that you have mentioned right

so over here what I'm doing is I'm going

to mention the details of an employee

who work on a specific project so for

that I'm going to do is I'm going to

just create a view over here so as I'm

creating so I'll type in create view

works on and then I'll mention the

condition as

select first name last name and project

name

from

employee project and works on

where

SSN

is equal to essn and project number is

equal to project number right so that is

basically the project number matching

from the project table to the works on

table and the SSN matching from the

employee table to the works on table

right and then I'll just execute this

particular query right once you execute

this particular query you see an output

that you know query returns successfully

now if I just refresh this particular

views you'll see a view named as works


on with the columns that you've

mentioned that is first name last name

and the project name now if you want to

see the data present in this particular

view what you can do is you can just

mention select star from and then you

mentioned the view name that is works on

one right and then if I execute this

you'll see the output right so that is

basically the data that is automatically

present in our view and the view is

created by deriving data from other

tables like the employee table the

project table and the works on table so

that's how guys basically you can create

a view now let's say you know you want

to drop a view dropping a view is also

really simple guys you have to type in

drop View and then the view name right

so if I mentioned works on one and then

if I end with a semicolon you'll see

that you know the drop view is

successful so if I just refresh this

particular section you'll see that you

know there's no view available so guys

that's how basically you can drop view

also

so guys that was all about views I'm not

going to go into depth of how you can


create more complicated views and all

because I've given you a basic

understanding of how views are created

and how you can drop the views also rest

I leave with you to practice please

remember the fact that you know I'm just

giving you all the basic concepts so

that you get started with postgresql but

if you have to get a good understanding

of all the databases then make sure you

have good practice on that note let's

get started with the next topic for

today's session that is procedures so

procedures are basically a section of

code so basically you can understand

procedures as a section of code or

functions which you can save you know

and then you can reuse it right so

whenever you want to save a section of

code or maybe a function and then you

want to keep reusing it that's where

stored procedures come into the picture

so for example let's say you know you

want to create procedures right so what

I'm going to do is I'm going to create a

new table let's stop with the example of

employees and work songs and so on let's

move on with a new example let's say you

know I create two tables so I'll mention

create table and then I'll mention let's


say the table name table first table to

be tbl1 and then I'll mention the column

to be tbl1 ID and then let it be int now

similarly I'll create another table also

so let me just change it to table 2 also

and then now what I'll do is I'll just

execute this particular two statements

right so if I just refresh this section

over here

right so now you will see that you know

instead of six tables now there are

eight tables so let me just minimize the

others so that you have no confusion

right so we have two tables that is tbl1

and tbl2 now let's say you know you want

to create a procedure such that you know

you want to insert values so basically I

don't want to write insert into

statements 110 times what I'm going to

do is I'm going to just create a simple

function through which you can insert

values so to insert values what you can

simply do is I'll mention create

procedure

and then let's say mention the procedure

name to be insert values and now let's

say you know we mentioned what values

have to be inserted let's say you know

value X has to be inserted in table 1


and value y has to be inserted in table

2. so I mentioned X integer

and Y integer and then what I'll do is

I'll mention language

SQL because it is a form of SQL as

dollar dollar and then I'll mention

insert

into

tbl1 that is basically my first table

values X right and then I'll mention

insert into tbl2

values y after that I'll just end this

section with double dollar and semicolon

and then what I'll do is I'll basically

call this particular function so this is

basically how you create a procedure but

yes if you want to reuse a procedure

then you have to call that particular

procedure right so for that I'll use the

functions call insert

values

and then I'll mention let's say one two

right so these are basically the two

values that I want to mention in table

one and table two so the table one

should be inserted with value one and

then table two should have the value 2.

and now what I'll do is I'll execute

this particular section completely once

I execute this particular section


completely you'll see an output at you

know call query has been returned

successfully right now let's just use

the select statement to see whether you

know the value has been inserted or not

so let's say I'll mentioned select star

from table one and then similarly I'll

mention select star from table two so if

I just print select star from table one

you see the value to be one right I hope

that you can see now similarly if I

mentioned select star from table two

you'll see the value to be 2. so that

means our values have got inserted so

guys this is a really simple example

I've just taken two tables with a single

column now you can have any number of

columns and then you can mention any

number of columns to be present over

here and then you mention the specific

values into the insert statements and

then what you just have to do is you

just have to keep changing the values

over here so for example let's say if I

do 3 4 over here again and then I

execute the statement call insert values

and then let's say you know I execute

the statement select start from the tbl1

so you'll see that you know apart from


one we also have the value 3. now

similarly if I do select star from tbl2

you'll see the output That Tune apart

from two we also have four so that's how

basically guys you can create stored

procedures well I think it was really

simple to understand how you can create

procedures and so on right

now in this session let's move forward

with the next topic that is triggers now

triggers are a set of SQL statements

which are stored in the database catalog

now these statements are executed

whenever an event associated with the

table occurs so a trigger is basically

invoked either before or after the data

is changed by either the insert

statement the update statement or the

delete statement and it only invokes

whenever there's an event associated

with the table

so now let's look into how you can

Implement triggers in postgres SQL so to

implement triggers uh what I'm going to

do is I'm going to create a table first

so let's say I create a table

audit

and then let's say you know I'm going to

consider employee ID right to be of CAD

type and nine characters since our SSN


is of 9 characters and then it should

not be null and then apart from that I

am also going to consider let's say you

know we have entry date right let's say

joining date or maybe entry date and

then we have text it's of Text data type

right and there should not be any space

because that is also a data type and

then I'll mention not null

now what I'm going to do is I'm going to

create a function and then I'm going to

create a function which returns a

trigger as a specific trigger and then

I'll use that particular trigger on the

employee table so let's do the same

now once I create this table ordered

what I'm going to do is I'm going to

create a function audit log function

which will basically return the trigger

as example table which will begin

whenever you wish to insert something

into the audit table now the trigger

example table will be created then so

let's just do the same so now since I've

created the table ordered let me create

the function right so to create a

function you have to type in create or

replace

function
audit log func that is basically you

know the function name that I'm giving

and then I mentioned returns

trigger as and then I'll mention the

trigger name Let It Be

example table right and then I'll

mention begin right so it will begin

then and then I'll mention insert into

audit where amp ID and entry date will

be mentioned and values will be new DOT

SSN a new SSN will be generated and then

automatically the current timestamp will

be taken as the entry date right so

that's how basically you can also use

timestamps also guys so basically what

I'm doing is whatever is the current

time I'm using that particular current

timestamp so I'll mentioned time stamp

and then what I'll do is I'll mention

return

new and then end so this is basically

the function that I'm creating so the

function basically says that you know it

will return a trigger as example table

whenever you want to insert something

into the audit table now as I was

talking about the trigger example table

we have to create that also right now

before that I forgot to mention

something over here that is you know you


have to mention example table that is

basically in language psql right so

you'll have to mention that particular

fact over here

now after that if you wish to create a

trigger you'll mention create

trigger will mention examples trigger

after insert on basically whenever

you're inserting

employee

for

each row I am going to execute the

procedure or the function that I just

created

so that is basically my audit log

function so I'll just copy from here

paste it over here and then finally I'll

mention the insert statement so what I'm

going to do is the insert since we are

doing on the employee table itself I'll

just copy this particular fact over here

and then what I'll do is I'll paste it

over here and let's say I mentioned

it's l and then I mentioned

and let's say I randomly put in details

right and then let's say I changed the

salary also so that there's no

redundancy anywhere right

so what have I done over here I've


basically created a table audit so this

audit table is basically like you know

whenever I want to insert into the

employee table a trigger will be created

so basically a trigger will be invoke

which says after Execute on you have to

mention the procedure right so basically

the procedure is basically the function

that we created that's basically it

returns to a trigger example table where

you know it inserts into the audit table

automatically that is basically the

employee ID that I've mentioned over

here and automatically the current

timestamp as the entry date so let's see

what happens so what I'll do is I'll

execute from here to here

and let's just check if everything is

selected yes and then I execute all

right it says syntax error at employee

ID value current oh it's because the

current timestamp spelling is wrong over

there so let's just correct that

now I'll again execute this particular

section again

it still says that you know there's an

error over here yes that's because you

know I've missed com over here and then

I'll put the bracket so I've removed the

brackets and then I have to put the


comma and then again let's try executing

this particular section

it says that you know the key super SSN

is not present in the table employee

right so that's because we cannot

randomly do and we have foreign Keys

present so let's just randomly choose

any superson let's say triple three

double four four times five right

and now I'll go back and now let's

execute again

once I execute again you can clearly see

an output that in a query returned

successfully right so let me just

refresh tables and let me just refresh

triggers so once I refresh tables you'll

see that you know there's an employee

table

and then we also see there is an audit

table and the order table has the

columns employee ID and entry date right

and then we have a trigger function

which says audit log function is

basically the trigger function that we

just created now if I wanted to see the

data from the audit table I'll just

choose

select star from audit

and then you'll see automatically the


employee ID and the date which is

basically the current time is generated

so that's how guys basically you can use

triggers so with this we come to an end

of the data manipulation commands I hope

you've understood all the commands and

the syntaxes and the statements that I

just showed you now let's move forward

with the next set of statements that is

the data control language commands now

the data control language commands as I

previously mentioned in the starting of

the session is basically used to provide

rights and privileges to the users to

access database views tables and so on

so basically there are only two

statements that you need to understand

in this particular section that is the

grant statement and the revoke statement

so let's consider the grant statement so

the grant command is basically used to

Grant privileges to the databases or

tables for example let's say you know we

consider the table one we created over

here so if I right click over here and

go to properties and let's say I go to

Securities you see that you know there's

no grantee privileges there's nothing

present over here because there are no

privileges granted to this particular


table so let's Grant permissions to this

particular table so what I'm going to do

is I'm going to type in Grant

select on then I'll mention the table

name that is table 1 2 and I'll mention

public

and then I'll just execute this

particular query you'll see that you

know the query has been returned

successfully and now what I'll do is

I'll right click over here go to

properties and then go to parameters and

then go to security over here and then

you'll see that you know automatically

we have granted a public privilege to

this particular table now let's say you

know we want to Grant privileges on

basically the command insert on right so

whenever there's some insert on we want

to Grant privileges to the public so

anybody can insert into this particular

table now let's say you know we want to

Grant insert on privileges to the

employee table right so basically

anybody can insert into this particular

table so that is basically Grant insert

on employee to public

if I just execute you see the output of

query returns successfully right so now


what I'll do is I'll just go to my

employee table over here

go to properties go to security and

you'll see public and then you'll see a

privileges of a right basically all so

that's how basically you can grant

privileges guys now you can also revoke

back your privileges let's say you know

you want to revoke back the privilege

that you just gave so for that you just

have to use the statement revoke right

so you'll type in revoke insert on

employee and then instead of two you'll

mention fra so you'll mention revoke

insert on employee from public right so

you'll just execute this particular

query and then we'll go to properties

again over here go to security and then

you'll see that you know there's no more

public privilege present over here so

guys that's how basically you can

control privileges and rights for your

databases and tables so guys that was

about data control language commands now

moving forward the next type of commands

that we have is the transaction control

language commands so the transaction

control language commands come into the

picture when you want to make sure that

you know the transaction in the database


is meeting all the standards that is

basically the asset properties so asset

properties are basically a term which

the consistency isolation and durability

so basically if you want to make sure

that you know your database is making

sure that the Transaction properties are

met then you have to use this

transaction control language commands so

to use transaction language control

commands what I'm going to do is I'm

going to perform transaction on table

one right so let me just see what values

are present in table one so let me just

see

I forgot to mention from over here so

it's Select Staff from table one and

then you'll see one free right now what

I'm going to do is I'm going to insert

around values till 10 so let's insert

all the other values I'm just going to

copy it from my doc over here

so since I have already one and three

values present over here what I'm going

to do is I'm not going to insert these

values so I'll just remove these

and then I'll just execute them right so

you'll see that you know data has been

inserted into my table now let's begin a


transaction when I say begin a

transaction you have to use the syntax

known as begin so you'll type in begin

and then let's say you know we want to

delete all the values which have the ID

greater than 5 right so basically all

the Tuple values which have the either

greater than Phi have to be deleted so

for that we are initializing a

transaction and then I'll mention delete

from and table 1 where table one ID so

let me just check the column name that's

tbl1 ID

is greater than 5. so I mentioned begin

so basically my transaction will begin

and then what I'll do is I'll delete so

let's just do that right so you can see

that you know the transaction is running

on and then we have deleted till file

now let's say you know if I want to roll

back rollback is basically I don't want

it to occur right so when I hit on

rollback you'll see that you know

automatically all the 10 values will

come back right so if I just use the

syntax of Select star from table one

you'll see the output of 1 to 10 again

so what you should understand from over

here is basically that you know the

begin is basically used to begin the


transaction and the rollback is

basically used to roll back from the

previous transaction so what I've done

is that I started the transaction and

then I deleted the values greater than

Pi so all the values got deleted now

when I hit on roll back what happened is

that you know the transaction got rolled

back then automatically all the values

got retrieved so that's how basically

you can do roll back now similarly you

can do commit right so what I can do now

is I can type on Commit over here and

then I can begin a transaction again

right so so once I begin a transaction

again and once I delete all the values

greater than Phi and then when I hit on

Commit you cannot roll back right so all

the values will be deleted whose ideas

will be greater than 5. so if I just

execute this particular statement you'll

see that you know you only have one to

five values now similarly you can also

about the transaction using the

statement aboard so guys that was all

about transaction language control

commands now let's move forward with the

next topic that is how you can export

and import data well guys exporting and


importing data is really simple for

example let's say you know I want to

export and import data of the table one

values right so what I'll do is I'll

right click over here and then go to

import export option and then what I'll

do is I'll mention the file name right

so basically I'm exporting and I'll

search for let's say demo.csv right so

now demo.csv is present in my e folder

right I'll choose that and then I'll

click on create once I click on create

you'll see that you know if I want to

replace well I have a pre-existing file

so I'm just allowing it to replace well

you can do that right and then you'll

click on OK once you click on OK you'll

automatically see that you know the

details have been copied right so what

I'll do is I'll go over here go to

e-fold domain and go to demo.csv so in

the demo.csv you can see that you know

we've got the data one to five because

we just had one row column that is one

to five and we just deleted the other

values so that's how guys basically you

can also export and import data it's

really simple in PG admin now finally

coming to the final topic for today's

session that is the uuid data type Now


The UU ID data type is basically the

data type which is based to uniquely

identify a particular value right for

example as I was talking in employee I

said SSN right so for every value I had

to insert an SSN basically I had to

incertain Value maybe if you don't want

to do it what you can do is you can just

directly use this particular extension

and then you can directly use that

particular value so now let me just

shift back to my PG admin now let me

close this particular part let me scroll

back

and now let's say you know we want to

see first what are the available

extensions right so I'll just type in

select star from PG hyphen available

extensions

so I'll mention this and I'll click on

execute once I click on execute you'll

see that you know we have name we have

default value we have installed version

and we have comment right so we have a

lot of available extensions but what I

want to use is the uuid OSB right so if

I scroll down more you'll see this

particular one right that is uuidosp

that's what we want to use over here


so initially if you know if you do not

have this extension what you can do is

you can just create this extension so

you'll type in create extension and

mention if not exists and then you'll

mention

uuid hyphen OSP so this has to be in

single quotes

and then you'll just execute this so let

me just execute this by dragging this

down so it says it's not fine oh yes it

has to be in double quotes itself that

was my bad

so when you create extension if not

exist uuid OSP you see an output of you

know create extension now what you can

do is you can just directly select from

the available extension now once I

create the extension and then if I

select uuid generate V4 you'll see that

you know automatically a new ID is

getting generated right now the next

time I execute this particular statement

again you'll see that you know a

different ID will be generated so that's

how basically you can use uuid as a

primary key for the table so for example

in the social security number of

employee table you could have used in

this now in that scenario you don't have


to sit and mention the SSN over there

you can just put the specific function

that is uuid underscore generate

underscore V4 and automatically you see

that you know every time you hit the

query you'll see a new ID will be

generated right so guys that was all

about uuid data type now you can use

uuid data type as a primary key to

uniquely identify your data type

[Music]

what is database management system and

what are its different types

database management system or most

commonly known as dbms is a software

application used to access create and

manage databases with the help of dbms

you can easily create retrieve and

update data in the databases a DVM is

consists of a group of commands to

manipulate the database and also acts as

an interface between the end users of

the database so if I have to just

summarize tbms for you then dbms allows

the users to define the data to update

the data to retrieve the data and also

for the administration of the users when

I say Define the data it allows the

users to create modify and delete the


definitions which Define the

organization of the database when I say

update the data what I mean by that is

that you know it provides access to the

users to insert modify and delete the

data from the database coming to

retrieve data it allows the users to

retrieve the data from the database

based on the requirement and finally

coming to administration of users it

registers the users and monitors their

action and enforces data security

maintains data security monitors

performance and deals with the

concurrency control so guys that was

about dbms now there are mainly four

types of tbms that is the hierarchical

dbms the network dbms the relational

dbms and the object oriented dbms

talking about the hierarchical one as

the name suggests this type of database

management system showcases a style of

predecessor and successive type of

relationship so you can consider it to

be similar to a tree wherein the nodes

of the tree represent the records and

the branches of the tree represent the

fields coming to relational database

management system this type of database

management system has a structure which


allows the users to identify and access

the data in relation to another piece of

data in the database in this type of

database management system the data is

stored in the form of the tables coming

to the network database management

system the network database management

system supports the many-to-many

relationships wherein multiple user

records can be linked and finally coming

to object oriented database management

system this type of database management

system uses small individual softwares

called objects and and here each object

contains a piece of data and the

instructions for the actions to be done

with the data so if you ask me if you

popular database management softwares

then they have MySQL postgres SQL Oracle

sqlite Mario DB and Microsoft SQL Server

now all these softwares are based on

different types of database Management

Systems available in the market so it's

completely based on the user's choice or

I would say your choice on which type of

database you want to work on and what

type of dbms would benefit you more

so I hope that you've understood what is

dbms and what are the different types of


dbms now let's move forward with the

next topic for today's session that is

SQL structured query language or

pronounced as SQL or sometimes also

known as SQL is a standard language for

dealing with the relational databases

now to explain you further let me take

an example for you now if two people

want to communicate with each other then

they have to use certain language which

is understood by both of them right so

if we consider these two people as one

as the user and other as the database

then the language which is used to

communicate between these two is nothing

but the structured query language so

similarly how a language has a grammar

and various rules on how it could be

used even SQL has its own directives SQL

is effectively used to insert search

update delete and modify the database

records and it doesn't mean that you

know SQL cannot do things beyond that it

can do things beyond that also it can

provide you Integrity checking it can

also provide you with embedded DML which

is used for general purpose programming

languages it has various sets of

commands to create different kinds of

views tables and other networks to


understand the database effectively and

many such more so guys this was about

the basics of SQL and dbms if you want

to learn more about SQL then you can

refer to our session on what is SQL and

I'm sure you'll get a better idea of

what is SQL but since this session is

based on SQL Server let's get into the

main topic for today's session that is

what is SQL Server now Microsoft SQL

Server is basically a relational

database management system which

supports the structured query language

and comes with its own implementation of

the SQL language which is known as the

transact SQL or the T SQL so it

basically has an integrated environment

to handle SQL databases which is nothing

but the SQL Server management studio now

the key components of SQL Server are as

you can see on my screen we have a

database engine and this component is

basically used to handle storage rapid

transactions processing and securing the

data coming to SQL Server service this

service is used to start stop pause and

continue the instance of the Microsoft

SQL Server moving on to the next

component which is the SQL Server agent


the SQL Server agent service placed the

role of the task scheduler and is

triggered by any event or as per the

requirement coming to SQL server browser

this service is used to connect the

incoming request to the desired SQL

Server instance coming to SQL Server

full text search this is used to let the

user run full text queries against the

character data in SQL tables coming to

SQL Server VSS writer this particular

service allows backups and restoration

of data files when the SQL Server does

not run moving on to the next component

that is SQL Server analysis services

that is ssas this service is used to

provide data analysis Data Mining and

machine learning capabilities the SQL

Server is also integrated with python

and R for advanced data analytics coming

to SQL Server reporting Services which

is SSRS as the name suggests this

service is used to provide features and

decision making capabilities including

integration with Hadoop finally coming

to the last component that is SQL Server

integration services that is ssis this

service is used to perform the ETL

operations for different types of data

from multiple sources of the data so I


hope that you've understood what is SQL

Server

now let's move forward with the next

topic for today's session that is

features of the SQL Server so the first

one is user experience so when I say

user experience what I mean by that is

that you know SQL Server can be used on

various operating systems like Windows

Linux and Docker so you just have to

develop once and deploy anywhere with

their consistent experience from

on-premise to Cloud right not only this

but they make sure that you know you as

a user get a consistent experience from

on-premise to the cloud and also provide

easy to use tools and the connectors so

you can use the Azure active directory

and the SQL Server management Studio to

manage your database infrastructure

across on-premise SQL server and also

Microsoft Azure so isn't that great guys

now moving on to the next feature the

next feature is availability so when I

say availability again what I mean by

that is that you know SQL Server make

sure that you know it provides High

availability and disaster recovery so

with this you can gain Mission critical


uptime fast payload easy to set up and

load balancing of the readable

secondaries with the enhanced SQL Server

versions so you can get unified

solutions for high availability and

disaster recovery on Linux and windows

not only this but you can also put up an

asynchronous replica in the Azure

virtual machines for the hybrid high

availabilities so that was about

availability guys moving on to the next

feature that is performance so when I

say performance what I mean by that is

dinner you can scale your price and

performance in a parallel manner so SQL

Server makes sure that you're your real

world application performance benchmarks

are set and then your application using

the SQL Server database is not failed

down or is not turned down right so you

can get great performance for your

application and it is also one of the

highest performing data warehouses

moving on to the next feature that is

analytics so when I say analytics what I

mean by that is that you know SQL Server

provides the built-in analytics or you

can say the built-in database Advanced

analytics so with the help of the

built-in analytics and the SQL Server


machine learning services using R and

python you can move beyond the reactive

and into predictive and prescriptive

analytics by performing Advanced

analytics directly within the database

so by using multi-threading and

massively parallel processing you'll

gain insights faster than using open

source R and python so guys that is one

major plus point of SQL Server now

moving on to the next feature that the

security so security as the name

suggests I would say that you know it

provides less vulnerable databases so

you can make sure that you know your

data is protected in a proper manner and

it is less vulnerable to any other major

attacks not only this but you can also

make sure that you know you have levels

of security and compliance for the

databases now coming to the final

feature guys that is business

intelligence so obviously as the name

suggests business intelligence is almost

used in today's market in every company

and every company needs a manner to

understand and visualize the reports and

also gain insights right so SQL Server

provides you with this feature and


allows you to build comprehensive

Enterprise scale analytics solutions by

benefiting from the fast performance of

in-memory built into the tabular model

so basically what happens is that unit

reduces the time to insights using

direct querying against tabular and

multi-dimensional models so guys that

were the features of SQL Server so I

hope that you have understood what is

SQL server and its features so now that

you know the basics of database

Management Systems SQL SQL Server let's

move forward and install SQL Server so

to install SQL Server what you have to

do is you have to follow the steps that

you can see on my screen initially you

have to install the SQL server and then

you have to connect to the SQL server

using ssms that is the SQL Server

management Studio after that you have to

access your database engine I hope I'm

clear with these points

all right so let's start with the

installation of SQL Server so initially

what I'll do is I'll install the SQL

Server then I'll connect to the SQL

server using SQL Server management

studio and then I'll access the database

engine now to install the SQL Server


what you have to do is you have to go to

this official website of Microsoft

SQL Server download

right so I'll just go to this particular

page

and once you go to this page you see

these two options that is SQL Server

2017 on premises and on the cloud now

what this means is that you know you can

either use SQL Server locally on your

system or maybe on the cloud so now what

you have to do is you have to scroll

down this particular page and you will

see this option of developer and the

Enterprise Edition so here I'll be

downloading the Developer Edition so to

download you just have to click on this

option of download now

now you can see that you know the

application is getting downloaded so

once the application is downloaded what

you have to do is you have to double

click on this particular file and then

you will see a window opening up so

let's just wait for that to happen

so as you can see our application is

opening up now once the application

opens up you see various types of

installation types that is the basic


type the custom type and the download

Media so what I'll do is I'll just

choose the basics type so when you

choose the basic type you can select the

basic installation type to install the

SQL Server database engine feature with

the default configurations just remember

guys when you're choosing the basic type

you're installing SQL server with the

default configuration moving on to

custom type so when you select the

custom installation type to step through

the SQL Server installation wizard you

choose the features or I would say you

choose the configuration based on your

choice right so I would say if you're

using it on an Enterprise level or maybe

a complete company is using SQL Server

then I would say you can go forward with

the custom installation because you may

have few features or you may want few

configurations which must be same for

the complete users right so that's when

I would say you can go for the custom

one but if you're someone who is just

using SQL server on locally on your

machine and then you just want to get

hands-on experience on that I would say

go for the basic one right so on that

note I'll just choose the basic one


and then once I choose the basic one you

can see that you know we get this page

of SQL Server license terms so what you

can do is you can just go through the

license terms and then you can just

click on accept button so I'll just

directly click on the accept button and

once I click on the accept button you

have to next specify the SQL Server

installation directory right so that

means where you want to install your SQL

Server so I'll just let it be as it is

and then I'll click on install

now once you click on install you will

see that all the required packages and

the libraries are getting downloaded now

let's just wait for the installation to

complete

so as you can see the computer requires

a restart so let me just restart my

computer right so let's just increase

start

now once the installation has completed

what you next have to do is you have to

go to this customize option pillow to

basically configure your SQL Server

database right so I'll just click on

this customize option

now once you click on the customize


option this is a screen that you will

see so over here what you just have to

do is you just have to click on next and

once you click on next you'll basically

see that the files are getting installed

right so let's just wait for that to

happen and then you keep clicking on

next I'll tell you when you have to

configure for something so let's just

wait for that to happen

all right now once the installation

rules are also done the next thing that

you have to do is you have to choose the

installation type so since we are

performing a new installation we'll just

choose this option of perform a new

installation of SQL Server 2017 but yes

if you had any pre-installed SQL

versions then you'll choose the second

option right so I'll just choose this

option of perform a new installation of

SQL Server 2017 and then I'll click on

next

now in the next wizard that opens up you

have to choose basically the type of

Edition that you are installed initially

that is the Developer Edition or the

Enterprise so since I downloaded the

Developer Edition I'll just choose

developer and then what I'll do is I'll


click on next

now after that you have to read this

license terms and then just click on

this radio button of I accept the

license terms and then click on next now

in the next wizard that opens up you

have to choose the features which you

wish to install also you can choose the

instance root directory and then click

on next so what I'll do is I'll just

choose the features let's say database

engine and then I'll let the root

directory be the same and then I'll

click on next now after that what you

have to do is you have to name your

instance and then this will

automatically return an instance ID

right so I'll just name my instance

let's say edureka right and once I

mention my instance name you'll see that

you know automatically my instance ID

will be edureka so after that what I'll

do is I'll just click on next

now in the server configuration wizard

just click on next and then once you

click on next you'll be redirected to

this database engine configuration so

over here you have the windows

authentication mode and the mixed Port


so over here what I'll do is I'll just

choose the mixed mode and then I can

mention the password right so I'll just

mention the password and then I'll

confirm the password

and then what I'll do is I'll just click

on ADD current user and you'll see that

in automatically a user has been added

so this particular user will be the

admin after that as you saw I just

mentioned the password and then I'll

click on next now once we click on next

you can see the summary of the

installation like what are the

properties or the features which will be

installed so you can just go through

that and then what you can do is you can

just directly click on install so I'll

just click on install over here

and now let's just wait for the

installation to complete

now once the installation is complete

this is the wizard that you see that

means that your installation has

completed so I'll just click on close

and then with this we finish our

installation now the next step is to

connect a SQL server using the SQL

Server management studio so for that

what we'll do is we'll go back to this


particular screen and then I'll click on

install ssms

now once you click on install ssms

you'll see that you know you'll be

redirected to a web page so let's just

wait for that to happen

so guys this is a screen that you see

once you click on install ssms now what

you have to do is you have to just click

on this download option so I'll just

click on this download SQL Server

management Studio link and then once I

click on the link you can see that you

know the setup is getting downloaded

right so let's just wait for that to

happen again

all right now once the setup has been

downloaded just double click on this

particular file

and then you'll see this particular

screen so over here you can just choose

the location or the installation

directory for your SQL Server management

Studio I'll let it be as it is and then

I'll just click on install

now once I click on install you can see

that you know our SQL Server management

studio is getting installed so let's

just wait for that to happen and once


that is done what we'll do is we'll

basically access our database engine so

let's just wait for installation to

complete

now once the installation is completed

you see that you know restart is

required in order to do the complete

setup now once the SQL Server management

studio is installed you just have to

open your SQL Server management Studio

from the Windows Explorer so here you

can just type in SQL server and then

you'll see this icon so you just click

on open and once you click on open this

is basically what you see now over here

what you have to do is you have to

choose your server name so you can just

go for browse for more and just choose

server name and let's say we choose our

desktop ID edu breaker right that is

because that is the one that we chose so

we gave our instance ID to be Eddie

Eureka if you remember so I'll choose

that and I'll click on OK and then I'll

click on connect now once you log in

guys this is the screen that you see now

the next thing that you have to do is

you have to basically start your query

editor right so before we get into the

query editor and start using the


commands let's understand how does the

SQL Server architecture look like so the

SQL Server architecture mainly has few

components that you can see on my screen

so it has a server it has the relational

engine the command parser the optimizer

the query executor and the storage

engine coming to the server first this

is where the SQL services are installed

and the database resides moving on to

relational engine this contains the

query passer Optimizer and the executor

and the execution happens in the

relational Engine moving on to command

parcel well this checks the syntax of

the query and converts the query to the

machine language moving forward with

Optimizer this prepares the execution

plan as the output by taking statistics

query and the algebra tree as input

moving forward with the next component

that is query executed well this is the

place where queries get executed step by

step and the storage engine is

responsible for storage and retrieval of

data on the storage system manipulation

of data managing and locking

transactions so you have a transaction

log and then you have a data file you


also have a storage engine which has the

transaction manager the access methods

and the buffer manager after that we

have the relational engine well the

relational engine has the optimizer and

the command passer and the command

passer is connected to the query tree

and similarly we also have the query

executor which executes the query and

the optimizer optimizes the query

finally we also have a protocol layer

which has the Sni and then this is

connected to the SQL Server network

interface well guys this was about the

SQL Server architecture on a high level

by now I hope that you've understood and

got a good understanding of the SQL

Server now let's move forward and get

into the SQL command categories where

there are mainly four command categories

that we're going to consider that is the

data definition language commands the

data manipulation language commands the

data control language commands and the

transaction control language commands

coming to data definition language

commands well this consists of the

commands that can be used to define the

database schema moving on to data

manipulation language commands well this


deals with the manipulation of the data

present in the database coming to data

control language commands well this

deals with the rights and permissions

and the controls of the database system

and finally coming to transaction

control language commands and this

consists of the commands which deal with

the transaction of the database so I

hope that you've understood what are the

SQL command categories so before we move

forward with the First Command category

that is the data definition language

command category let me talk a little

bit about the SQL Server data types well

there are various kinds of SQL Server

data types present so when I say data

types I mean what kind of data can be

stored in your databases so you can

store exact numeric data types the

approximate numeric data types the date

and time values the character strings

the Unicode character strings the binary

strings and many other data types so

talking about the exact numeric data

type well the exact numeric data type is

used to basically store the numbers so

in this data type you have other data

types like the numeric the time in small


lint bigint and so on moving on to

approximate numerics well approximate

numerics are used to store decimal or

float value so you have the flow data

type and the real data type coming to

date and time as the name suggests this

type of data type is used to store the

date and time values in the database so

we have date small date time date time

date time two and so on moving on to

character strings well this particular

data type is used to store the character

strings like care wirecad text and so on

the Unicode character strings are used

to store the n-care vargaron and text

after that coming to Binary strings

binary strings as the name suggests

again I used to store the binary values

so we have binary where binary and image

values in this particular data type and

in the other data type sections we have

data types like the cursor the row

version hierarchy ID unique identifier

and so on well I would say once you get

a Hands-On practice on how to write

queries and how to manipulate data in

your database you'll definitely

understand which type of data type you

need to use or you need to use to define

your columns so I hope that you've


understood so on that note let's start

with the first language command category

that is the data definition language

commands so to demonstrate the data

definition language commands what I'm

going to do is I'm going to create few

queries and then I'm going to explain

how you can use that so now what I'll do

is I'll just add a query pane so to do

that what I'll do is I'll just go to

this new query option and then you'll

see that in automatically our query pane

opens up let me just zoom in a little

bit so now that I've zoomed in let's get

started with the session so initially

what I'll do is I'll just create a

database so to create a database you'll

type in a command create database and

then you'll mention the database name

right so let's say I mentioned the

database name to be students now after

that you just have to select this

particular statement and click on

execute now once you click on execute

you clearly see that you know the

commands have completed successfully so

our database has been created if I just

refresh this particular section and then

I go to databases
you see that you know we've got our

students database right so now to

perform any action in a database you

have to first use that database so for

that you'll just type in use and then

you'll mention the database name to be

students right and then what you'll do

is you'll just execute again right and

once you execute again you'll see that

you know the commands have been

successful so that means whatever

actions that you're going to perform is

going to happen under this particular

database now after that what you can

simply do is you can just create a table

right so to create a table again you

just have to use this command of create

table right so I'll just mention create

table and then you can mention the

table's name so let's say we just

mention it to be students info right and

then in Brackets what you have to do is

you have to mention your column names

and its data types so the column names

could be like student ID let's say it to

be of int right next let's say student

name let's say VAR care of 8000

similarly we can have parent name

again of varca let's say 8 000

after that you can have phone number


let's say big int because it's going to

have a large value after that we can

have address of a student right so I'll

just mention address of a student again

bearcat

then I'll mention City let's say Vaca of

8 000 then I'll mention country

again of worker

of eight thousand after that you can

just close this and then once you do you

can just execute this particular

statements so after the statement is

executed what you can do is you can just

refresh this particular section go to

databases go to students and in students

you'll see that you know if you go into

the table section we find a table of

students info so that's how guys

basically you can create a table also

now for example let's say you want to

drop a table now dropping a table is

also similar you just have to use the

command drop table and then you mention

the table's name so that it is students

info right so I'll just mention students

info right and then what I'll do is I'll

just execute once I execute and then if

I refresh you'll see that you know a

table is gone so let's just wait for it


to happen

if I go to table section you see that

there is no table present so that's how

basically you can create a table and

drop a table now similarly you can also

drop a database also so to drop a

database what you have to Simply do is

you just mentioned drop database

and then you mentioned the database name

which was students so I'll just execute

and then once I execute you see an error

that you know we cannot drop the

database because it's in current use

right so what you can do is you can just

create another database let's say

students one and then we use students

one

and then you can go back and drop this

database of students right so once you

drop this database of students you'll

see that in a new database has been

created that is students one and the

students database has gone right so

let's just wait for that to happen right

so as you can see we just have one

database that is students one right so

that's how guys basically you can drop

and create the databases and the tables

now the next command that you need to

know in the ddl commands is the alter


command but before we start with the alt

command what I'll just do is I'll just

use this particular database and then

I'll just create back this table again

right and then what I'll do is I'll just

write the alt command so for example

let's say you want to add a column of

blood right so what you'll do is you'll

just mention alter table then you'll

mention the tables name that the

students info and then you'll mention

add blood group so that is basically a

column name that we want to add and then

we'll mention where care of 8000 right

and then I'll click on execute once I

click on execute and go to tables and

then once we go to this particular table

and go to columns on the left hand side

you clearly see that our blood group

column has been added similarly you can

drop the same column also so what you'll

do is you'll just copy paste this right

and then what you'll do is you'll just

change the add function to draw function

right so you'll mention alt table and

then you'll mention the table's name and

then you'll mention drop and then you'll

mention blood group right so if I just

execute this
oh I'm sorry I have to remove this

particular data type also because we're

not creating the column right so I'll

just execute this particular statement

again all right it says blood group is

not a constraint now this is one of the

most common errors as you know people

just remove the command and then try to

remove that column but what you have to

do is you have to mention that it's a

column right so for that you'll mention

all the table table name and then you'll

mention drop column and then the column

name after that you'll click on execute

and then once you click on execute and

refresh you see that our blood group

column has gone so that's how basically

guys you can add a column or you can

delete a column now for example let's

say you want to add a column and then

you want to change the data type also

right so you want to do both you want to

add a column and then you want to change

the data type also so what you'll do is

you'll just mention all the table we'll

just copy paste this particular

statement and then we'll mention all the

table students info that is basically a

table name and then let's say we want to

add a date of birth column right so I'll


just mention dob over here

right and let's say our data type to be

date right and then I'll just execute

once I execute you see that you know our

column will be added now what I'll do is

I want to change the data type right so

to change the data type what you do is

we copy paste the statement again

and then I'll just remove this

particular part and I'll mention all the

column and then I'll mention column name

so that was date of birth and then I'll

mention the new data type right so let's

say I want it to be date time right so

I'll just mention date time and close

right so that's how basically you could

play around with ddl commands guys it's

very easy and it's very interesting to

learn with so guys that was about the

alt command now let's say you know you

want to truncate a table so when I say

truncate the table what I mean by that

is that you know you want to delete the

information present in the table but the

table itself is not deleted but before

that let's just include some information

into the table so to include information

you have to mention insert into and then

you'll mention table's name right so


that's students info right and then

you'll mention values and then let's say

I mention few values right so I'll just

mention

so I'll just execute this particular

statement oh it says column name or

number of does not match the table

definition

we see this error because you know I

forgot to drop the column of dob so I'll

just drop the column so to drop the

column I'll just mentioned Auto Traver

drop column and then I'll mention dob

right so let me just copy this

particular section from here

and then I'll execute the statement and

once I execute the statement I'll

execute the statement again and then you

will see that you know our values have

been inserted now to truncate the table

what you have to do is you basically

have to use the syntax of truncate so

you'll just mention truncate

and then you'll mention the table name

our table name is students info so I'll

just mention students info and then I'll

click on execute once I click on execute

we see that you know the commands have

completed successfully right initially

our columns have few values but now our


columns have no values over there right

apart from this if you want to also

rename a table or rename a database you

have to use the command of SP underscore

rename so this is something different

from the other databases as generally

the rename command or the queries used

but in SQL Server you have to use SP

underscore rename and then you'll

mention

students one that is basically our

database name and then you'll mention

students info and now you'll mention

what you want to change it to right

let's say we want to change it to info

students

right and then let's just execute

okay it says it cannot find so I'll just

remove this particular part and execute

and once I execute you can see that you

know our table name has changed so what

I'll do is I'll just refresh this left

hand side and I'll go to students one

I'll go to tables over here and then you

can see that you know it has changed to

info students so I hope I'm clear with

the ddl commands guys well these are a

few basic commands that you need to know

before you start handing and


manipulating databases on that note

let's take a look at the next topic for

today's session that is keys in the

database now the different types of keys

used in the database are the candidate

key the Super Key the primary key the

alternate key and the foreign key now

coming to candidate key candidate key is

a set of attributes which can uniquely

identify a table so a table can have

more than a single candidate key and out

of the chosen candidate case a single

key is chosen as a primary key coming to

Super Key this is a set of attributes

which can uniquely identify a tuple so

candidate Keys unique keys and primary

keys are super keys but the vice versa

isn't true coming to primary Keys the

primary keys are used to uniquely

identify every Tuple so a table can have

only one primary key and that key will

identify every Tuple uniquely in the

table moving on to alternate key the

alternate keys are those candidate Keys

which are not chosen as the primary key

and finally coming to the foreign key

the foreign key is an attribute that can

only take the values present as the

values of some other attribute and that

is the foreign key to the attribute to


which it refers so Guys these were the

various types of keys in database so

it's completely based on your

understanding or how you want to design

your database model that which key

should be primary key and which Keys

together can uniquely identify a table

and so one apart from this we also have

few constraints which are very popular

in the database so next in the session

let's take a look at the popular

constraints available in the database so

the constraints used in the database are

not null unique check default and index

let's talk about not null first the not

null constraint ensures that a column

cannot have a null value right so that

is very simple as the name suggests it

ensures that you know a column cannot

have any null value so if you just

assign the constraint of not null to any

particular column then automatically you

have to mention a value into that

particular column to enter that

particular tapple into the database

coming to Unique the unique constraint

make sure that you know all the values

in the column are different so basically

when you mention a constraint unique to


a specific column then automatically

what happens is that all the values

present in the column are unique so two

or more values cannot be the same coming

to check constraint this constraint

ensures that all the values in a column

satisfy a specific condition so whenever

you mention the check constant you'll

mention a condition and all the values

which satisfy the condition can be

present in that particular column any

value which doesn't satisfy the

condition cannot be present in that

particular column moving on to default

well this constraint consists of set of

default values of a column where no

values is specified right for example

let's say while entering values in a

column you forget to mention a few but

yes while creating the table or maybe

while adding a constraint you add the

constraint of default for that

particular table let's say 10. so all

the places where you do not mention any

value 10 will be automatically added to

that particular places and finally

coming to the last type of consonant

that is Index this constant is used to

create and retrieve data from the

database very quickly right if you want


to create and retrieve data from the

database very quickly then you have to

use the index constraints so now that

I've explained you keys and constraints

in database let me just switch back to

my SQL Server management studio and then

what I'll do is I'll just execute few

commands or queries based on this

particular section

so let's get started so what I'll do is

I'll just copy this particular section

from over here right and then let's say

I just add a segment so that it's clear

to us and then I'll copy paste over here

and then let's say we want to use the

not null constraint so for example let's

say we want to make sure that you know

the student name and the address of the

student is definitely present or maybe

when the user is entering values its

mandate for the user to enter the

student name and the address of student

right so then what we'll do is we'll

just mention not null constraint over

here right and again I'll just mention

not null constant over here right and

then what I'll do is I'll just create

this particular table right now once

this table is created what I'll do is


I'll just copy paste this insert

statement from over here I'll paste this

and let's say you know I just remove the

address part right so I'll just remove

this particular section and then I'll

mention null and then I'll click on

execute when I click on execute you can

clearly see the error that you know

cannot insert the value null into the

column because you know the column does

not allow none that is because we have

given the normal constraint to the

address column right so that's how

basically you can use the not null on

create table now similarly if you want

to use not mill on the alt table what

you basically have to do is you just

have to mention the alter table

statement and then at the end you have

to mention not null for example let's

say I want to mention all the table

students info

right and then I'll mention let's say

alter column

and then I'll mention phone number

right and let's say

I mentioned int sorry end not null right

and then I'll just click on execute

and once I click on execute you can see

that here the command has been


successful so whatever happens you

cannot mention the null values in the

phone number column so guys that's how

basically you can use the normal

constraint on the create and the alt

table now let's move forward with the

next constraint that was the unique

constraint

also while working on the unique

constant let's just check how to add the

primary key so what I'll do is I'll just

drop this particular table so I'll just

mention drop tables students info

right I'll just execute right and then

what I'll do is I'll just copy paste

this section paste it over here so what

I'll do is I'll just mention the unique

constraint over here and then what I'll

do is I'll mention primary key

and in Brackets I'll mention student ID

right after that I'll just click on

execute and once I click on execute you

can see that you know the student ID

will be unique so every ID will be

unique and since every ID will be unique

it will uniquely identify every Tuple so

that could be the primary key so that's

how basically you can add the unique

constraint for a single column now let's


say you want to add unique constant for

multiple columns right so similarly what

I'll do is I'll just drop stable again

I'll copy paste the section paste it

over here remove the student ID and

remove unique constraint from over here

and then what I'll do is I'll just

mention constraint right and then I'll

mention the constraint name that I want

to give so it could be UC let's say

students info and then I'll mention

unique and in the brackets I'll mention

student ID and let's say we want the

phone number also to be unique right so

we'll mention a phone number

right and then what I'll do is I'll just

execute again so once I execute again

you can clearly see that you know our

table has been created so if I just

Refresh on the left hand side

right and then what I'll do is I'll just

go to the constraints part over here or

you can see that you know if I go to the

column section over here you can see

that our constraints are clearly visible

on the left hand side over here also if

I go to the key section where you can

see that you know our students info

constant which I just mentioned over

here is clearly present over here so


that's how guys basically you can add

unique constraint on multiple columns

now similarly if you want to add unique

constant on an ALT table it's very

simple you just have to mention alter

table and then what you do is you

mention the table's name as we

previously did and then we'll mention

add and we'll mention the constraint

that is unique constraint and over here

we'll mention the column on which we

want to add the unique constraint right

so I want to add it on my student ID so

I'll mention student ID and then I'll

just execute right so that's how

basically you can add a unique

constraint on an alter table also now

similarly if you want to drop the

constraint also guys you just have to

mention all the table and then you'll

mention students info and then what

you'll do is you'll mention drop and

then you'll mention constraint and then

you'll mention the constraints name

right so for example let's say I'll

mention this particular name and then

I'll just execute the statement now if I

just refresh this left hand side and

let's just open again so I'll go to


tables

I'll go to students info and then if

I'll just refresh

so I'll go to tables I'll go to students

info and then if I go to Keys we see

that you know there's no UC students in

for constant present but then this

particular constraint that we had just

added before on the order table

statement that is present so that's how

basically you can add the unique

constraint now let's move forward with

the next type of constraint that is the

check constraint

well the check constant as I previously

mentioned is used to add a condition

right so for example let's say you know

you want to add the check constant while

creating the table itself so to do that

what I'll do is I'll create a table but

before that let me just drop this table

again and now what we'll do is we'll

just copy paste this particular section

put it over here remove this part

and let's say you know we want our

country to be India so all the values

which could be entered into the table

must have the country value to be India

right so we'll just mention check over

here and then in Brackets I'll mention


country

equal to I'll mention

India right and then what I'll do is

I'll just execute this particular

statement so after that let's say if I

want to insert a statement so for that

I'll just copy paste this particular

section let's I put it over here and

over here let's say I just mentioned any

value like

nice Road

right and let's say we mention over here

Germany right and I'll just try to

execute and once if I try to execute you

can clearly see the error that you know

insert statement conflicted with the

check constraint the conflict occurred

in the databases because you know the

column country has to be India right and

then we have mentioned Germany so now

what you can just do is you can just go

back change the country to India and

then you can insert the value so that's

how you can use the check constant on

the create table now let's say you want

to use the check constraint on the altar

table now similar to that of the unique

constraint what you'll do is you'll just

mention all the table and then you'll


mention the table's name and then what

you'll do is you'll just mention add

check

and in Brackets you'll mention country

equal to India and then you'll execute

now that's how basically you can add the

check constraint on the alter table

similarly if you want to give the name

to the check constraint well that's not

necessary that you always give the name

but yes if you're handling on an

Enterprise level and then you're

handling a lot of databases then giving

a name must be a priority right so to

add the name what you simply do is

you'll just use this author table

statement again right and then you'll

mention the table name and over here you

have to add constraint

right and then you'll mention the name

so let's say I mentioned the check

let's say constraint name right and then

what I'll do is I'll mention the check

condition

and that is India right so if I just

execute the statement again you'll see

that unit completely works and if I

refresh on the left hand side go to

tables go to students info go to

constraints you'll see that you know a


constraint name has been added up right

so similarly you can drop a constraint

while dropping a constraint is again

same you have to use or to table

students info and then you just mention

drop constraint and I you can just

mention the drop consonant name so I'll

just execute this particular statement

again and you'll see that you know a

constraint has been drawn so guys that

was about the drop constraint now let's

go forward with the default constraint

where the default constant as I

previously said is used to add the

default value so what I'll do is I'll

just drop this table again right and

then what I'll do is I'll just copy

paste the section paste it over here

I'll just remove this particular section

and then let's say our default country

values India right so I'll just mention

default

sorry spelling mistake and then I'll

mention India so basically all the

values which will be inserted into the

table will have the default value India

so whenever there is no value that you

enter for example let's say you are

entering 10 values and out of 10 5 you


have entered as Germany and five we've

not entered any of them then all those

other five will go will get the value as

India right so I'll just execute this

particular statement and then what you

can just do is you can just check with

the insert statement so now similarly if

you want to add the default constraint

with the auth table you just have to

again use all the table students info

and then what you'll do is you'll just

mention add constraint and let's say you

give the constraint name to be let's say

default

let's say country right and then you'll

mention the condition that is default

which will be India and then you'll

mention the column name which is country

and then I'll click on execute all right

it says that you know the column is

already born I'm sorry so what we'll do

is we'll add let's say City

and we'll just change it to City over

here

and let's say we change it to h y d

right and then I'll execute again once I

execute you can see that you know it's

clearly working now to drop the default

constraint also it's very simple you'll

right click over here and just choose


delete and then once you choose delete

you can just choose the object name and

click on OK right so once you click on

OK you'll automatically see that you

know your default constraint has been

dropped now one more way to drop the

default constant is by using the alter

table you just have to mention all the

table students info and then mention

drop constraint and then you'll just

execute this particular statement right

so that's how basically you can drop the

constraint guys now let's move forward

with the next constraint that is the

index constraint so the index console as

I said is used for the fast creation and

retrieval of the database so for that

you'll mention create index and then

let's say we mention the index name to

be let's say student

name right and then I'll mention on

which table that is the student's info

table right and then on which column so

we want student name from the students

info table right so I'll just create

this particular Index right and then

what I'll do is I'll just refresh this

particular section

and over here what I can do is I can go


and check on my left hand side now if

you want to delete your index constraint

what you'll do is drop index and then

you'll mention the index name so I'll

just mention index name and then I'll

click on execute it says that you know

we must specify the table name and the

index name so I'll just mention the

table name also so I'll just mention

table name dot index name right and then

I click on execute and then you can see

that in our index constraint has been

dropped so that's how guys basically you

can create order and drop your

constraints I hope you've understood

what are keys and constraints and how

you can manipulate your data based on

those keys and constraints right now

let's move forward in the session and go

to the next SQL command category that is

the data manipulation language commands

so the data manipulation language

commands are used to manipulate or I

would say retrieve the data in the

databases based on your requirement

right so to do that what I'll do is I'll

initially insert the values into the

table and then what we can do is we can

just manipulate the data so what I'm

going to do is I'm going to show you the


use command the insert command update

command delete merge the select commands

the cube the roll up offset fetch top

and pivot and apart from that we'll also

discuss the various kinds of operators

which can be used so without any further

Ado let's get started so initially as I

was talking about the use command the

use command is used to use a database

right so to use a database as I just

mentioned previously you just mentioned

the command use and then you mention the

database name that is students one now

after that what you have to do is if you

want to insert values then you insert

the values using the insert statement so

as you can see on my screen it's insert

into and then you mention the table name

values and then you can mention the

values required so now what I'll do is

I'll just drop this particular table so

that all the constraints are removed

right so I'll just mention drop table

students info

and then again we'll create a table

right so I'll just copy paste from over

here

right so once I just create this table

what I'll do is I'll just mention the


insert commands right so since I've

already explained you the insert

statement before I'm not going to do

that again so the insert statement is

simply used to insert the value so there

are mainly two ways through which you

can insert the values into the table

either you mention the column names and

then you mention the column values else

you can just mention the column values

right so I'll mention insert into

students info and these are the column

names and then these are the specific

values similarly if you mention insert

into values and then we can mention all

the values which need to be inserted

into the table right so I'll select all

of them and then I'll execute and once I

execute you can see that you know the

table has values so to check whether the

values are inserted or not what you can

simply do is you can just type in Select

Staff from let's say students info right

so we'll mention students info and then

I'll execute and once I execute you can

see that you know all our values have

been inserted now let's say you know you

want to update some data present in this

particular database right for example

let's say for student ID with student ID


1 let's say we want to set the student

name to be ahana and then City to be am

the bar right so what I'll do is I'll

mention update and then I'll mention

students info and then I'll mention set

student name that is basically a column

name right and then I'll mention the

value that is let's say ahana

right and then also I'll mentioned City

don't forget to put a comma over here

right so I'll mention City equal to am

the bath right and after that what I'll

do is I'll mention the condition where

student ID equal to 1. right and then

I'll just execute this particular

statement and once I execute the

statement let me execute this particular

statement again and then you can see

that you know the student name has

changed to ahana and the city has

changed to Ahmedabad so that's how

basically you can update your data guys

now let's say you want to delete data

from database so to delete data you'll

just mention delete

from

and then you'll mention students info

where and then let's say we want to

delete a tuple with the student name


ahana right so I'll just mention student

name equal to and then I'll mention

ahana and then if I just execute this

particular statement again you see that

you know our student ID with the student

name Anna has been gone so guys that's

how basically you can insert update and

delete values present in the database

now let's say you want to use the merge

command well the merge statement is used

to perform the insert update delete

operations on a specific table where the

source table is provided so when you

have two tables let's say table a and

table B and then let's say table a is

the target table and table B is the

source table and then we have few

matched rows so when we merge both these

tables we can see that you know we can

perform the insert update delete

operations on the tables right well the

syntax to perform the merge operation is

very simple you just mentioned merge and

then you mentioned the target table name

using the source table name and then you

mentioned the merge condition and then

if it matches then you mentioned update

statement if it does not match then you

can mention the insert statement and if

it does not match by any Source then you


mentioned the delete statement so to

understand the merge statement let's

just say we create two more tables right

so what I'll do is I'll just create

table let's say sample Source table and

let's say the columns to be student ID

of in type

right and then I'll mention student name

of let's say Vaca 8000 again

right and then we'll mention the marks

column of in type

now similarly I'll just create the

target table also so before executing

I'll just change the name to Target

right so I'll just mention sample Target

table and then I'll just execute both

these statements right now after that

what I'll do is I'll just insert few

values into the source table and the

target table so I'll just mention insert

into and then we'll mention sample

Source table and then let's say we

mentioned values and over here we

mentioned let's say first person with

name vihan

and let's say the marks to be 87.

similarly let's just mention two more

records right so I'll just copy paste

right I'll just change this to 2 3 let


me change the names and the marks

now similarly I'll just insert it to the

Target table also so I'll just change

the table name to be sample Target table

so I'll copy paste from Who We Are

and then I'll let the first record be

the same let's say one behan and 87 and

let's say we change it to 67 and please

sort of

and let's say we change it to 55.

now what I'm going to do is I'm going to

merge both these tables and that means

I'm going to merge the sample Target

table and then I'm going to merge it by

using the sample Source table right so

for that I'll mention the statement

merge

sample Target table and then I'll

mention Target

I'm sorry

using and then we'll mention the source

table so it will be sample

so stable

and then I'll mention Source on and in

Brackets I'll mention Target

dot let's say we match it to store in

tidy that is basically a condition must

match our source student ID right so

we'll mentioned Source Dot

student
ID so when it matches what we want to do

is when matched and

Target dot student let's say name is you

know same as

Source dot student name

right or Target dot you want marks is

same as let's say

Source Dot

marks right then we want it to update

set we want to update Target dot student

name equal to oh I'm sorry the target

spelling is wrong

The Source dot student name right comma

we also want to match the marks right

target dot marks equal to

Source dot marks

when not

matched by Target then we want to insert

right so we'll it mention insert and

brackets will mention student ID

comma student

name

marks right and we'll mention values

we'll mention Source dot student ID

similarly Source dot student name and

Source Dot

monks right and after that when it

doesn't match right so what we want to

do is when not matched we want to delete


right so we'll just mention by source

then delete

right so I hope that you've understood

right so what I'll do is I'll initially

insert the values into the sample Source

table and the target table right and

then what I'll do is I'll just show you

what are the values present so I'll just

mention select star from sample table

that is our sample Source table

so you can see that you know we have

three tuples that is with vihan Mansa

and Ani are having 87 92 and 74 and then

when we have the sample Target table

we have again three tuples with vihan

Mansa and saurabh having 87 67 and 55

marks so now what I'll do is I'll just

include this merge statement

spelling mistake right so I'll just

mention we're not matched and then I'll

just execute so when I execute this

particular statement you see that you

know two rows have been affected and

then we see completion time right so if

we just again click on Sample Target

table we see that you know we have our

Target table now having behan as 87

Mansa is 92 and an a as 74. initially

our Target table had we had as 87 man

says 67 and sort of as 55 right so that


means our values have changed and our

values have come from the source table

so that's how guys basically you can

merge two or more tables well that was

about merging column guys now since I

was using a lot of Select statement let

me show you a few actions which you can

perform on the select statement so for

example let's say you want to select a

few columns right you'll just mention

select and then you'll mention the

column name so let's say I'll mention

student ID

and let's say we mentioned student

name right so it should there should be

a comma over here from

students info right so if I just execute

this particular statement you see all

the values of student ID and student

name from the students info table now

similarly if you want to select all the

columns you'll just mention Select Staff

from the table name so that's how you

can use the select statement now let's

say you want to select the top three

records from the table so you'll just

mention select top three star and then

you'll mention the table name so that

will be let's say students info and when


I execute this particular statement you

see that you know we get the top three

statements that is the values for the

second student third student and the

fourth student now similarly you can

also find out the distinct values in a

specific column also for example let's

say we want to find out the distinct

cities present right so we'll just

mention select distinct

and you'll mention City

from and you can mention students info

right and then let's execute if I

execute you can see that you know we

have Mumbai Bangalore Delhi Kolkata as

the distinct city is present now moving

forward let's say you want to use the

order by Group by and the having Clauses

in the select statement well to do that

it's really simple guys you just have to

use those Clauses for example let's say

you want to select all the students from

the students info table sorted by the

let's say parent name so for that we'll

mention select

star from students info and then we'll

mention order by parent name right and

over here if you do not mention anything

it will be ascending order by default

but let's say if you want it in a


descending order you'll just mention the

keyword descending

right and then you'll click on execute

and you can clearly see that you know

our students are sorted by the parents

name so it starts with s and then goes

to a and then if you just remove this

particular section and then you execute

again you'll see that you know our fifth

student with a parent named Agarwal will

be first on the list now that's how you

can use the order by statement now this

was just for one column now let's say

you want to sort the data present in the

table with different columns right so

let's say we want to sort the students

from the students info table by parent

name and also the student name so we'll

just mention student name and then what

I'll do is I'll just execute and when I

execute you can see that you know since

we haven't mentioned anything whether it

should be ascending or the descending

order automatically the parent name

comes in the ascending order so our

fifth student comes first on the list

and then the order follows similarly if

you just replace this so for example if

you just put the student name first and


then you mentioned the parent name and

then you execute the statement you'll

see that you know the results are

different because our student name will

be first sorted in the s sending order

now apart from this what you can also do

is you can sort the data present in the

table either in the ascending order or

in the descending order for different

different columns right so what I mean

by that is that in a student name can

have the snake order and the parent name

can definitely have the descending order

so let's do the same so I'll just

mention ascending over here and over

here I'll mention descending right and

then I'll execute

so once I execute you'll see that you

know the student names are sorted in the

ascending Manner and the parent names

are sorted in the descending manner so

that's how all the students in the

student info can be sorted by the parent

name in the descending order and the

student name in the ascending order so

guys that was about the select statement

now this is one of the most popular

statement which is used while

manipulating data in the databases

because you know this is one of the


easiest way to retrieve data and this

statement is used with lot of commands

and other queries to retrieve data in

the format the client wants now moving

forward in the session let's say you

know we want to list the number of

students from each City now to list the

number of students from each City what

you have to do is you have to take care

of the aggregate functions so the

aggregate functions are basically those

functions which are used to calculate

the sum average the count and the range

the first and so on so don't worry I'll

be talking about them later in the

session but for now if I just have to

implement and show you you can just

mention select count and then you can

mention let's say student ID

right and then you can mention City

from the table name that a student's

info and then what you can do is you can

simultaneously group them by city right

so because we want to count the number

of students from each City we just group

them by City And then we use the count

function and then we execute the

statement you see that you know Mumbai

has one student Bangalore has one Delhi


has one and Kolkata has one so guys that

was about this particular query now

let's say you want to use the grouping

sets well grouping sets were introduced

in SQL Server 2008 and were used to

generate a result set that can be

generated by Union all of the multiple

simple Group by clauses so the syntax is

also very simple guys you just have to

mention select and then you mention the

column names from the table name Group

by and then grouping set and then the

brackets you mentioned all those column

names which have to come under the

grouping sets so for example let's say

I'll just modify this particular query

right so I'll just mention select and

then I'll remove the count function

let's say I mentioned select student ID

and let's say I also mentioned student

name right and then I count the number

of cities from the students info table

and then I grew by and then I again use

the grouping sets so I'll mention

grouping sets and in Brackets what I'll

do is I'll mention the grouping sets

right so for example let our first set

be student ID

student

name
right so let me just press on enter so

that's clear and also let's say we have

City now let's say in the other set we

just have student ID

right and in the next one I just have

student name right so I'll just put in

the bracket and in the last one let's

say we just have a city right so these

are very sets that we have created right

and now we can just execute this

particular query you can see that you

know student ID student name and no

column name that is basically a count of

City from students info and then it's

grouped by basically these four sets

that the student ID student name City in

one set student ID in the second set the

student name in the third set and the

city in the fourth cell for example

let's say for student ID which is null

and student name is null the account is

one

so guys that's how you can use the group

bike clause and the grouping sets

together now let's say you want to use

the having Clause well the having Clause

is generally used in the scenario where

the where keyword cannot be used right

so if You observe generally in the


select statements we use the where

keyword so in the scenario where the

where keyword cannot be used we use the

having Clause so let's say you know if

you want to use the having Clause let's

say we want to count the number of

students from a specific City and let's

say you know their count should be one

and should be ordered by let's say

student ID with descending order right

so what we can do is we'll do select

count and then I'll mention student ID

comma City

and then I'll mention from obviously the

table name right students info and then

I'll mention Group by City having count

and then over here I'll mention student

ID again

equal to one I'm sorry equal to one has

to come out and then let's say we order

by count let's say student ID

in the descending manner right so I'll

just execute the statement we can see

that you know Mumbai Bangalore Delhi and

Kolkata have come with their count

having one so that's how you can use the

having Clause guys now let's say you

want to create a backup of this table

that is the student's info table so to

do that what you'll do is you'll just


mention select star into and you'll

mention the backup tables name so let's

say we mentioned students backup

from and then I'll mention the table

name that is students info right and

then I'll just execute and then you'll

see that you know automatically the

backup has been created

now this is where we just included all

the columns and the tuples from the

students info table to the students

backup table now let's say you just want

to select only few columns from the

students info table well to do that what

you'll do is you'll just mention few

columns that is Select and then you'll

mention ABC column from the table apart

from this you can also mention

conditions also for example let's say

you want to retrieve only those students

who are from the city Pune so you'll

just mention whatever column values that

you want to retrieve like select student

ID student name and so on into the table

that is the table name from students

info where the city will be Pune so for

your better understanding let's just

write that so select star into let's say

we mentioned Pune students


from students info where

city is equal to Pune right and then

I'll just execute so if I just execute

this particular statement you'll see

that you know we have no values present

because there was no student with the

city Pune so now what you can do is you

can just go back and change the city

name and then maybe drop the table and

create the table again so that's how you

can play around with the select

statement guys now let's move forward

with the next DML command that is the

cube command well I would say that you

know the cube is an extension of the

group by Clause so it basically allows

you to generate the subtotals for all

the combinations of the grouping columns

specified in the group by Clause so for

example let's say you know you want to

use the cube statement so what I'll do

is I'll just mention

select student ID right and let's say we

also mentioned count we mentioned City

from students info

and then we mentioned Group by and then

we mentioned Q

and I'll mention student ID

order by student ID

right and then I'll just execute so when


I execute you can see that you know we

have four students so each student

belongs to a single City now similarly

to the cube statement you can use the

roll-up statement so the Roll Up is

again also an extension of the group by

clause and this allows you to include

the extra rows which represent the

subtotals so these are referred to as

the super aggregated rows along with the

grand total row so similarly to that of

the cube Clause I'll just mention for

the roll up Clause so I'll mention

select student ID account City from

students info Group by and then over

here I'll mention roll up and then I'll

just remove this order by statement

right so you can just click on execute

and then you'll see that you know the

null equal to four will come at the

bottom of the table so when you executed

the cube statement What You observe was

that you know the Super aggregated Value

that was basically the subtotal came in

the first row but when you execute the

role of statement you see that you know

it comes in the last row so that was

about the cube and the roll up guys now

moving on to the next DML command that


is the offset Clause the offset Plus is

used with the select and order by

statement to retrieve a range of Records

it must be used with the order by Clause

since it cannot be used on its own also

the range that you mentioned must be

equal or greater than zero right so if

you mention a negative value then it

shows an error so to demonstrate this

let's just create a table right so I'll

just mention create table let's say

offset marks

and then I'll mention

marks end so that will be our table

column right and then what I'll do is

I'll just insert values into this right

so I'll just mention insert into and

let's say I'll mention offset marks and

let's say I mentioned a few random

values right so initially I'll just

execute this particular statement and

after that what I'll do is I'll just

execute the statement before that I

forgot to mention values over here right

so I'll mention values and execute this

and similarly I'll execute the other

statements so let me just copy paste

and I'll just change the values over

here

and I'll execute again now after that


what I'll do is I'll use the offset

statement so I'll just mention select

star from I'll mention the table name

that is offset marks order by Max and

then we want to mention offset one row

so that means our first value which had

61 so when we use this order by Max we

see the table values to be sorted on 61

62 64 65 and 65 and after that when we

say offset 1 marks the first Tuple will

be deleted so that is the reason we get

only 62 64 65 and 65. so that's how we

can use the offset statement guys now

let's move forward with the next one

that is the fetch statement well the

fetch Clause is used to return a set of

number of rows so it has to be used in

conjunction with the offset class right

so to do that what we'll do is we'll

just mention select star from offset

marks and then we'll mention order by

let's say marks

right and then what we'll do is we'll

mention let's say offset three rows and

then fetch next two rows only right so

we'll just fetch the next two rows after

leaving the first three rows right so if

I just execute this particular statement

we get the two rows that is 65 and 65.


now similarly you can also select the

top three records from a table you buy

using the top keyword as I had mentioned

previously also so if we just mention

select top three star from offset marks

you'll get the top three tuples from the

table so guys that was about the offset

clause and the top class now let's move

forward with the next one that is the

pivot well the pivot is used to rotate

the rows to column values and run

aggregations when required on the

remaining column values now the syntax

of pivot is also very simple guys you

just mentioned select non-pivoted column

name and then you've mentioned First

quivoted Column name as a column name

and then so on till the last pivoted

column name as a column name from and

then you mention a select query which

produces the data as a pivot and then in

the pivot section you mentioned the

aggregation function for the column name

so what I'll do is to give you detailed

understanding I'll consider an example

so I'll just create a supplier table

which has a supplier ID the days of

manufacture the cost the customer ID and

the purchase ID right our supplier ID

should not be null right and then what


I'll do is I'll just insert a few values

into it right so let me just execute

this statement first right after that

I'll just go back and then copy paste

this section

and then what I'll do is I'll just

insert after the values have been

inserted into the table now what I'll do

is I'll just select the customer ID the

average cost as the average cost of the

customer from the supplied table and

then I'll group it with the customer ID

right so for that I'll just type in the

command select customer ID

comma average of

cost

as and then I'll mention let's say

average

cost of customer

from supplier table

Group by let's say customer ID

right and then I'll just execute the

statement so once I execute the

statement you see that you know we have

the customer ID 11 and then the average

cost of all the customers with the

customer ID 11 is 1676 similarly all the

customers with the customer ID 22 have

the average cost of customer as four six


five four and similarly for the third

one that is 33 we have 5238 right now

what we're going to do is we're going to

create a SQL pivot table with one row

and three columns So Over Here If You

observe we had three rows now what we'll

do is we'll just create the pivot table

with one row and three columns right so

for that we'll just type in the command

select let's say average cost of

customer as let's say we just change it

to cost

according to customers right and then we

mentioned one one

two two

and three three and then we mentioned

from and in the inner section we

mentioned select customer ID right and

then we mentioned cost from supplier

table

as let's say so stable and then what

we'll mention is we'll mention pivot

and in Brackets when mentioned average

cost

for customer ID

and in Brackets we'll mention

one one

two two

three three

as pivot table right so I'll just


mention

pivot table

right and then I'll just close right so

I've just mentioned select average cost

of customer as customer according to the

customers one one two two three three so

we have one row and three columns we

want to select customer ID and cost from

the supply table are so stable and then

continue right and so I'll just execute

so once I execute you can see that you

know the average cost of customers has

been named as customer according to the

customers and we have one one two two

three three so where if I just drag you

can see that you know the average has

been put over here so basically in our

previous table which were rows have now

become the columns so that's how guys

you can create a SQL pivot table now

similarly you can unpivot it all so for

example let's say I create a table

sample table and in that I mentioned

supplier ID let's say int AAA of n type

let's say BBB of n type and CCC of n

type

right and then I just type on go and

then I mentioned insert into let's say

sample table and then I mentioned values


right in Brackets I'll just mention

let's say one three five six right

similarly I'll just mention the other

values also so let me just copy paste

all right and then I'll click on go so

I'll just execute the statement right

and now what I'll do is I'll just show

you the value so I'll just mention

select star from sample table right and

I'll just execute this once I execute

this so you can see that you know we

have three rows and four columns right

so we have the supplier ID and then we

have a a b b and CC now what we'll do is

we'll unpivot it so to unpivot it what

you have to do is you have to mention

select

that says supplier ID that is basically

our column names and then we'll mention

customers

and let's say products

from

and brackets again I'll mention select

supplier ID

and then I'll mention AAA

BBB and CCC

and I'll mention from sample table right

so I'll just give a space

give sample table

and then I'll mention unpivot


right and over here I'll mention

products

customers

in and in Brackets again I'll just

mention the values that is AAA BBB and

CCC

as let's say example

right and then I'll just put on go

right and then I'll click on execute

once I click on execute you can see that

you know what we had as four columns in

three rows has now been converted right

so for every customer that is AAA the

products show three the values that we

have entered previously are shown for

example let's say a which had value 398

are now put into three different rows

similarly goes for BBB and CCC so that's

how you can unpivot the table also guys

well that was about a little bit section

of the DML commands now if you want to

know in depth about SQL pivot and

unpivot I'll leave a Blog Link in the

description box below and you can refer

to that well guys that was about this

part of the section now let's move

forward with the next part of the

session that is operators now I would


say operators is a very important part

of the session because operators play a

very important role to handle and

manipulate data I would say different

ways to retrieve the data right so the

different operators present in the SQL

Server are the arithmetic operators the

assignment operators The bitwise

Operators the comparison operators the

compound operators The Logical the scope

resolution operators the set operators

the string concat and the aggregate

functions so talking about the

arithmetic operators first well the

arithmetic operators have the addition

subtraction multiplication division and

the moduli sign right so you can just

add subtract multiply divide or find the

reminder coming to assignment the

assignment operators are used to assign

a value to the variable coming to The

bitwise Operators The bitwise Operators

are used to perform the bitwise and or

an exclusive or operations moving on to

the next operators that is the

comparison operators well the comparison

operators are the relational operators

which are used to perform comparison

operations like greater than less than

equal to greater than equal to not equal


to less than equal to and so on moving

on to the compound operators well the

compound operators are used to perform

the compound operations of addition

subtraction multiplication division

moduli and function or function on the

sort function coming to logical

operators where the logical operators

are used to perform logical operations

between the data so these are generally

used in the nested queries so the

different kinds of logical operators are

as you can see on my screen like all and

any between exists in like not R and sum

right I'm not going to go into the depth

of each one of them because you know

it's completely based on your

understanding of how which operator will

benefit you better but I would say the

more you practice the more you will have

an understanding about the different

operators moving on to the next type of

operator that is the scope resolution

operator well this operator is used to

define the scope and after the scope

resolution operators we have the set

operators so in the set operators we

have the union operator the intersect

operator and the minus operator so the


union operator is used to combine the

rows from both the query so when you

have a left query and right query and

you perform Union operator and then you

apply the unit operate later then

automatically you will see that you know

it will combine rows from both the

queries coming on to the intersect

operator while the intersect operator is

used to keep the rows which are common

in both the queries right so for example

there could be few common queries in

both the left query and the right query

then when you apply the intersect

operator only those queries will be

taken into account and finally coming to

the minus operator the minus or the

accept operator is used to keep the rows

from the left query which are not

present in the right query and the vice

versa right so when you have two queries

or the two tables let's say left query

and the right query when you say a minus

B's and it keeps all the rows from the

left query which are not present in the

right query and if you say B minus a

then it keeps all the rows from the

right query which are not present in the

left query right now coming to string

concat operators will the string concat


operators are used to perform various

actions on the string like you know

string concatenation then wildcard

characters to be matched to Wildcat

characters which match just a single

value or maybe multiple values and so on

and finally coming to aggregate

functions as I previously spoke about in

the session aggregate functions are used

to find the sum average count min max

first and last values so all of these

operators are very simple to use guys

for your better understanding let me

give you a few examples but I would say

the more you practice the more will you

benefit right for example let's say you

want to use the arithmetic operator

additions you can just mention select 40

plus let's say 60 and then you can just

execute once you execute you see the

output as 100 similarly for example

let's say you want to use the comparison

operators let's say greater than equal

to right so for that you'll mention

select star from let's say we choose the

table offset marks where marks is

greater than or equal to and then you

mention let's say 62. and after that

you'll just execute


so you can see that you know you will

get all those tuples which have marks

which are greater than or equal to 62.

now similarly you can also use the

compound operators also for example

let's say let's just declare two

variables so I'll just declare let's say

at the rate bar one of n type let's say

to be of 30 right and then what I'll do

is I'll just set it to be divided by

let's say 16 right so for that I'll just

use this compound operator and then

equal it to 16 right and then I'll

mention select at the rate where one as

example

right and then what I'll do is I'll just

execute

oh it says that we must declare it first

I'll just declare it first and then what

I'll do is I'll just mention where one

right I'll just set as 16 I'll just

execute it again and when I execute it

again you see the example as one that is

because you know when we divide 16 by 30

our quotient is one so similarly if you

use the moduli simple over here then

you'll see the reminder right so I'll

just execute it again and then you see

that reminder to be 14. so that's how

you can use the compound operators now


let's say if you want to use the logical

operators right for example let's say if

you want to find out the marks between

62 and 65 what you'll do is you'll just

mention select star from and then you'll

mention offset marks where and then

you'll mention marks which is a column

name and then you'll mention between

and then you'll mention 62 and which is

again a logical operator and you'll

mention 65. right okay my bad this has

to be select

and then I click on execute so if we get

all the marks between 62 and 65. now for

example let's say we want to find out

those marks which are greater than 62 or

marks which are equal to 67 so what

we'll do is we'll just change this

statement so select star from offset

where marks and then we'll use the

comparison operators are greater than 62

and or I would say

or Max equal to what did I say it was 67

and then I'll execute again and then you

see that you know marks greater than 62

are just 64.65 so we get that and since

there are no marks which are equal to 67

we do not get that now let's move

forward with the next one that is the


like operator so the like operator is

one of the most popular question asked

in your interviews now this is since

people often get confused between how to

use the like operators right so for that

I'll just show you a few example so

let's say you know we want to find out

all those students name starts with

let's say s we'll just mention Select

Staff from and then we'll use students

info right where I'll mention student

name like

and then what I'll do is

I'll mention s

right and then I'll mention the

percentage symbol

so when I execute we see that you know

only one student with the name Shania

because her name starts with s is in the

result set well that was about this

query guys now for example let's say you

know you want to find out the student

name whose name starts with m and the

name has six letters right so what I'll

do is I'll just mention select star from

student name like and then I'll mention

M and then I'll mention five underscores

and then mention a percentage symbol

right and then I'll click on execute

when I click on execute we again see


only one query because mansas name

starts with m and has around six letters

including M itself so the five

underscores where for the rest five

letters and M was the starting letter

and percentage symbol represents

anything can be there after that right

so that was about this particular query

now let's say we want to find out all

those tuples whose student name starts

with m and then ends with a right so

I'll just change this particular query

only I'll just remove the underscore and

then put a percentage symbol and mention

a what I mean by this particular

statement is basically that you know the

student name should start with M should

end with a and any number of letters can

be present in between well that was

about this particular query guys now

let's say you want to use the scope

resolution operator to access the get

root member of the hierarchy ID type

well to do that what I'll do is I'll

just declare a variable so let's just

declare

at the rate example ID of hierarchy ID

type and then what I'll do is I'll

select this particular ID right so I'll


just mention select add the rate example

ID

equal to

hierarchy ID and then I'll mention the

scope resolution operator and then I'll

mention get root

after that I'll just print at the rate

example ID that is basically a variable

to string so basically I'm just

converting it to string right and then

what I'll do is I'll just execute this

particular set of statements

and then once I execute the set of

statements you see this output right so

that's how you can use the scope

resolution operator also guys well that

was about this particular operator now

let's say you want to use the string

concatenation operators well to use the

string concatenation Operator Let me

just consider the example of Select

let's say we take student name right so

I'll just mention student name right and

then I'll put a plus Mark over here that

is I'm using the string concatenation

operator right and then what I'll do is

I'll just use single quotes

right I'll put comma and then I'll put a

plus sign again and then choose parent

name
right and then I'll just use the

analysis function that is I'm combining

these two columns and putting it as

another column and let's say I just

mentioned it to be name from

students info right and then I execute

so as you can see the output you can

clearly see that you know we've got a

name column which has this concatenated

values of the student name and the

parent name so if you want to give a

space then you have to mention spaces

over here right and then you click on

execute again and then you can clearly

see that you know the space is visible

right so that's how you can use the

string concatenation operators guys now

let's say you want to move forward with

the aggregate functions where aggregate

functions were used before also when we

were doing the order by in the group by

Clauses For Your Right understanding

let's say if you want to just calculate

the average of all the marks you'll just

mention select and then you'll choose

average

marks right so that's basically a column

name and then you'll mention the table

name that is offset marks and then you


click on execute so once you click on

execute we get our average of all the

marks present so that's how you can use

the aggregate functions also guys now

let's move forward with the set

operators well as I explained before the

set operators consists of Union

intersect and the accept operations so

what I'll do is I'll just consider

another table which similar to that of

our student table so I'll just create

one more table so let me just scroll up

right and I'll just copy this particular

section

come down paste it over here change it

to let's say students details

right and then I'll also insert few

values right so let me just copy paste

from over here so that it's faster

so I'll just execute this particular

statement now and now once our table has

been created I'll just execute these

three statements again and now there are

two table students info and students

details and both of them have few values

now let's just perform the union

operation the intersect operation and

the accept operation so I'll just

mention select star from

students info
and then I'll mention Union and let's

say we mentioned Select Staff from the

table 2 that is students details right

so I'll just search for students details

right and let's just execute now once we

execute you can clearly see that you

know all our table values have been

inserted so we had few values in at

first table and a few values in our

second tables all the values got

combined into our third table right now

similarly if we just do the intersect

option so I'll just mention intersect

and then we can see the common values in

both the tables so I'll just mention

intersect and execute and we can see

that you know the fourth and the fifth

record are common in both the tables

when I type in students info except

students details all the tuples which

are present in students info and not

present in student details are given as

output and similarly if I just do the

reverse right so if I just change it to

students details accept students info so

let me just do that

and then I'll just do it to info over

here you'll see the opposite output

right so that's how basically guys you


can use the set operators I hope that

you've understood how to use the

different kinds of operators to

manipulate and retrieve and handle your

databases now let's move forward with

the next part of the session that is

nested queries now nested queries are

also one of the most popular Concepts

that you need to know because you know

nested queries are SQL queries which

have an outer query and an inner sub

query so the sub query is a query nested

within another query such as the select

insert update and the delete statements

so this was about the nested query guys

so as you can see on my screen we have

an auto query and then we can have a sub

query so what will happen is that you

know the first the sub query or the

inner query will be executed and

whatever output comes that output will

be the input to the outer query and then

we get the final output that was about

the nested queries guys so for your

better understanding if I have to give

you an example we can just write a query

like you know select student

name

and let's say parent name

from
we mentioned students info

right and then I'll mention where

address of student in and then we can

have an inner query which says select

address of student from students backup

that we had initially created

where

let's say country

is equal to India

right and now we can just execute this

particular query and then we get the

output so that's how you can type the

nested queries guys now let's move

forward with the next part for today's

session that is joins now joints in SQL

are commands which are used to combine

rows from two or more tables based on a

related column between those tables so

they are predominantly used when a user

is trying to extract data from the

tables which have one to many or many to

many relationships between them now

there are mainly four types of joints

that you have to understand guys that is

the inner join the left join the right

join and the full joint now the inner

join Returns the records which have

matching values in both the tables the

left join Returns the records from the


left table and also those records would

satisfy the condition from the right

table the right join Returns the request

from the site table and also those

records would satisfy the condition from

the left table and finally coming to the

full join the full joint Returns the

records which either have a match in the

left or the right table so for your

better understanding what I'll do is

I'll just consider an example so apart

from the students info table let's just

consider the subjects table right so for

that I'll just create the subjects table

so let me just type in create table

subjects and let's say we have

subject ID of n type right and let's say

we have student ID of in type then we

have

subject name of let's say wirecare type

and after that let me just insert few

values so I'll just mention insert into

subjects value 10 10 maths and 211

physics and 312 chemistry so I'll just

execute these statements now once the

statements are executed let's apply the

join functions so let's say we want to

apply the inner join right so we'll just

mention select

subjects Dot subject ID and let's say


students info Dot and we want the

student name right from both these table

from we want from subjects table that is

at table a and then we'll mention inner

join that is a joint condition and then

we'll mention the second table name that

is students info and will mention on and

after that we'll mention the condition

that the subjects

dot student ID must match students info

Dot

student ID right and then we'll just

execute this particular statement and

once you execute the statement we see

that you know there are no common values

present so that is the reason we do not

get any values

well guys that was about the inner join

now let's say we want to apply for the

left join right so what I'll do is I'll

just select students info dot student

name and let's say we also select the

subject ID from the subjects table and

let's say our first table is students

info right so that is what we are

considering over here and over here I'll

mention left join

and after that what I'll do is I'll

mention the other table name that the


subjects and then I'll mention on and

then what I'll do is I'll just match the

students info to student ID equal to

subject or subject ID and then let's say

we order it by the student name right so

I'll just mention students info

let's say student name

right now I'll just execute this

particular statement and then we can see

that you know we get all the values from

the left table that is the students info

table and then also those records which

match the condition from the right table

similarly if I apply the right join over

here you'll see all the records from the

right table and also those records which

satisfy the condition from the left

table now finally let's apply the final

type of joints that is the full outer

join

and then let me just execute and once I

execute we see that you know we get all

those records which have either a match

in the left table or the right table so

guys this was in short about the

different types of joints in SQL now if

you want to learn in depth more about

the SQL joints you can refer to my

session on SQL joins with that guys we

come to an end to the joints part of


this particular session now let's move

forward to the stored procedures I am

sure that you know you might have an

understanding of what stored procedures

are stored procedures are those reusable

units that can encapsulate a specific

business logic of the application so it

is a group of SQL statements and logic

compiled and stored together to perform

a specific task the syntax of stored

procedures is as you can see on my

screen right so you just have to mention

create or replace a procedure and then

you mention the procedure name and after

that you'll mention the parameters name

and then you'll use the aliases is or as

and then you say begin right and when

you say begin you declare the section

and then finally you end the procedure

so to demonstrate this let me just

create a procedure for you so let's say

we create

procedure let's say students

City

right and then we choose the parameter

name to be sat and let's say to be of

varca type 8000 right and after that we

choose as and then we select from

students info
and then we can mention where City equal

to at the rate and then we mention it to

either it as s City then we create go

and after that we mentioned select star

from students info again now once it is

created what you can do is you can just

execute the statement simultaneously

also so for that you'll just use in the

command execute right so execute

students city right and then you'll

mention at the rate s City because that

is the type of the variable that you've

created and let's say to be of Hyderabad

right and then you'll click on execute

so once you click on execute you can see

that you know you select all the

students from the students info and you

see that you know there's no student

from Hyderabad for example if you

mentioned Kolkata over here right so

I'll just mention Kolkata right and then

if I execute it again you can see that

you know we get an error that you know

there's already an object named student

City so I'll just execute this

particular section and we see that we

get only those tuples who say city has

Kolkata value so that's how guys you can

use stored procedures you just write the

code once and then you can keep using it


again and again like any other

programming languages so guys that was

about the stored procedures and with

this we come to an end to the DML

commands now let's move forward with the

next section of commands that is the DCL

commands so as I mentioned before the

TCL commands are used to Grant or revoke

privileges to a user so for example

let's say you want to create a user so

to create a user what you can do is you

can just mention create login

sample with we mentioned the password to

be edureka

so this will basically create a user so

I'll just execute the statement okay it

says that you know the sample user

already exists so I'll just mention it

to be sample one right and then I'll

click on execute and once I click on

execute you can see that you know my

user who's with the name sample 1 and

password redirect has been created now

what you can do is you can just use this

user to perform various actions rather

than only using the admin login

so this is how you can create a login

sample one with the password at Eureka

Now to create a user what you'll mention


is you'll mention create

and then you'll mention user edureka

right and for login and then you'll

mention sample one so to create a user

what you initially have to do is you

have to create a login for that

particular user and then you go forward

and create a user right so I've created

a login and then I'll just create this

user so I'll execute this and now this

particular user can be used rather than

just using the admin login credentials

now what you can do is now you can grant

and revoke any kind of privileges to a

specific user now for example let's say

you want to Grant few privileges for

this user edureka right so for that

you'll type in Grant

select on and then you'll mention the

table name let's say students info right

and then what I'll do is I'll mention

two and then I'll mention the username

that is at Eureka so I'm just granting

this privileges to this particular user

now similarly I can also revoke back the

granted privileges so I'll just go back

and choose Revo so I'll just mention

revoke over here and then I can just go

back and execute right so once I execute

you can see that you know no privileges


are there also if you want to check you

can go to security you can go to users

over here on the left hand side and then

you can choose edureka and then once you

choose edureka once you double click on

that particular user you can see all

kinds of permissions granted to this

particular user so since Nana granted

you can't see anything presently but yes

if you grant some then you can

definitely see over here so guys that

was about the DCL commands now let's

move forward with the next section for

today's session that is the TCL commands

or the transaction control language

commands well these commands are used to

handle the transactions in your database

to demonstrate this what I'll do is I'll

just create the table so I'll just

create a table and insert few values so

let me just copy paste the same

I've just created a table as TCL sample

with the student ID student name and

marks columns and then these are the

values which will be inserted right so

I'll just click on execute now once

these values are inserted now let's just

start our transaction right so to start

a transaction what I'll do is I'll just


mention begin try so that's a try catch

block which I'll come to later in the

session so don't worry after that I'll

mention begin transaction right and then

I'll mention insert into TCL sample

that's a table name and then I'll

mention values and let's say we

mentioned few values let's say 5 and

then I mentioned the name

and let's say we've mentioned other

values right so I'll just mention 56.

this need not be in code so I'll just

remove that

right and after that what I'll do is

I'll just mention update

TCL sample that's a table name and then

animation set student name equal to

let's say we mentioned the student name

to be Akash

where our student ID is 5.

also we want to update our TCL sample

table again and set our marks equal to

67

where our student ID

is 5 right after that we want to commit

this transaction

and then print

that

transaction

completed right so I'll just promote a


print on the screen and then I'll end my

try block right and begin my catch block

now and over here I'll mention rollback

transaction

and over here I'll mention again print

transaction

unsuccessful

and rolled back

after that I'll end my catch block

so if You observe over here what I've

done is I've just started my try catch

blog and then I've begin my transaction

after that I've inserted a value into

the table now after that I want the

value to be updated right so I want to

set the student name to be Akash with

the student at least five and this marks

to be 67 with the student ID is 5. after

that I want to commit the transaction

and print transaction completed and then

only if there is no error the try block

will end but if there is any error found

or any exception found then the catch

block will be executed where it will

print transaction unsuccessful and roll

back so what I'll do is I'll just

execute the statement okay I'm sorry I

missed a comma over here right and now

let me just re-execute the statement


again and once I execute this statement

you see an output that you know

transaction completed that means that

you know we have inserted this value

into the table and then we have also

updated the values right so I'll just

show you that so let me just type in

select star from TCL sample right so

when I execute you can see that you know

we have our fifth student with the name

Akash and the marks to be 67. now let's

say you know you set the marks to 67 by

zero and then let's just execute the

section again now once I execute the

section again you clearly see an output

that you know transaction unsuccessful

and rolled back that is because you know

we cannot set up marks as 67 by 0 as we

have given that you know marks column is

an INT column and then an end column

cannot have this particular kind of

values so that's how guys the

transaction control language commands

works right with this we come to an

enter the different SQL command

categories that you need to understand

about now let's move forward with the

final topic for today's session that is

exception handling well exception

handling in SQL Server is almost similar


to that of the other programming

languages it's the same as you handle

exceptions in all the other programming

languages you have a true block and then

you also have a try cache block so

talking about the pro block first or I

would say the throw Clause this class is

used to raise an exception and transfers

the execution to a catch block of the

try and catch construct if you want to

see the syntax the syntax is as you can

see on my screen you mentioned throw and

then you mentioned in the error number

and then you can mention local variable

message and so on coming to the try

catch Blog the try catch blog is used to

implement exception handling in transact

SQL so a group of statements can be

enclosed in a drive block so in case an

error occurs in the try block the

control is then passed to another group

of statements that are enclosed in the

catch block as we just saw in the

transaction control language commands so

the syntax is as you can see on my

screen it starts with begin try then we

mentioned few SQL statements then we

mentioned entry then we mentioned big

and catch and then we again mention few


SQL statements and then we mention end

catch so that's how you can do exception

handling guys so for your understanding

let me just give you a quick example so

let's say if you want to use the throw

Clause you'll mention throw and then I

said you'll mention the error number

right so let's say I'll mention five

thousand one hundred and let's say I

mention it as record does not

exist right and then what we can just do

is we'll put a comma and then put on one

and then when I execute this particular

statement you can clearly see that you

know message 51 000 and then you can see

that you know state line is one and the

messages record does not exist right so

that's how you can use the flow Clause

now similarly you can use the try and

catch block as you saw before so for

that you'll just type in big and try

right and let's say we select phone

number

Plus student name right so if you

remember our student name was of wirecat

type and our phone number was of pagan

type right so we cannot concatenate both

of them so I'll just mention phone

number concatenate student name from

students info and then what I want to do


is I want to do n try then I'll begin

the catch block right and then I'll

mention print

not possible

right and let's say I'll just mention

end catch

right and then we can just execute the

statement so when I execute this

particular statement you see that you

know no column name but if I go to

messages you can clearly see that you

know if the message shows not possible

right so that means a try block did not

get executed only a cash flow got

executed and shows the exception of not

possible that indicates the user that

you know we cannot add these two columns

so that's how you can perform exception

handling in Microsoft SQL Server guys

[Music]

let's look at the first question for

today's session that is mention the

differences between SQL server and MySQL

now this is one of the most popular

questions as as you know both of them

are relational database Management

Systems so if you have to give the

differences between SQL server and MySQL

then I would say SQL Server is developed


by Microsoft and MySQL was developed by

Oracle SQL Server is a licensed product

so you do not have the free edition for

it and MySQL is an open source software

right so if you want to know how to

install both of them I'll leave the

links in the description box below but

let me tell you over here that you know

you can easily install MySQL in very few

steps but when it comes to SQL Server

you have to enable few ports and name

pipes and then you have to follow a

proper step to configure the databases

so I would say if you have to compare

the installation step between both of

them then I would say installing MySQL

is very easy comparative to that of SQL

Server coming to the next difference SQL

Server supports C hash Java C plus plus

PHP Visual Basic Perl Python and root be

coming to my sequel MySQL also supports

various programming languages like you

know PHP Pearl python Ruby and so on

right so both of them offer quite good

amount of support to build various kinds

of applications using different

Technologies coming to the next

difference I would say SQL Server

doesn't allow any kind of database file

manipulation while running the database


whereas MySQL allows database file

manipulations while running SQL Server

allows query cancellation Midway in the

process but this is not the scenario in

MySQL as MySQL does not allow query

cancellation Midway in the process

moving on to the next difference while

backing up the data SQL Server doesn't

block the database but when it comes to

mySQL it blocks the database right and

coming to the next difference you can

say that you know SQL Server takes a

large amount of operation storage space

whereas that's not the scenario in MySQL

as it takes a less amount of operation

storage space coming to the last

difference that you know SQL Server is

available in the Express in the custom

mode and MySQL is away available in the

MySQL Community Edition and the

Enterprise Edition so Guys these are a

few differences between SQL server and

MySQL apart from that also you can

answer the interview by talking about

your personal experience while using SQL

server and MySQL right you might have

created databases in both of them and

maybe you have manipulated data using

both of them right so you can talk you


know what happens when you want to do a

specific set of actions in MySQL and SQL

Server so with this we come to an end to

the first question now let's move

forward with the second question that is

what do you understand by SQL Server

agent now SQL Server agent is one of the

most popular component of SQL Server

right so basically if you have to

explain SQL Server then you can just say

that you know SQL Server agent is a

Windows service which is used to

schedule and execute the jobs so here

each job contains one or more steps and

each step can contain a task so what

happens is that the SQL Server agent

uses the SQL Server to store the job

information and run a job on a schedule

now the main components of SQL Server

agent are basically jobs schedules

operators and alerts so if you have to

explain with an example over here you

can just consider the example like you

know if an Enterprise wishes to take the

backup of the company servers at 9 pm on

every Friday now what you can do is you

can just automate the stars and let the

task happen at the scheduled time but in

a scenario where a backup encounters an

error the SQL Server agent records the


events and notifies the corresponding

team so that's how you can use the SQL

Server agent guys well this was one of

the simple usage you can do it in a very

complicated way also so I would just say

that you know SQL Server agent is one of

the most important concept or you can

say the most important component that

you need to understand about Microsoft

SQL Server so moving on in this tutorial

on Microsoft SQL Server let's look at

the next question that has mentioned the

different authentication modes in SQL

Server now before I tell you the

different authentication modes in SQL

Server let me tell you that the

authentication mode is used for

authenticating a user in the SQL Server

so the authentication mode is selected

while setting up the database engine and

the different authentication modes

offered by SQL Server are basically the

windows authentication mode and the

mixed mode now the windows

authentication mode is used to connect

the server through a Windows account so

what basically happens over here is that

you know the server takes the computer's

username and password for authentication


purposes and also the SQL Server

authentication mode is disabled in this

mode coming to mixed mode the mix mode

is used to connect with an instance of

SQL server using either the SQL Server

authentication or the windows

authentication so in this mode basically

there's a username and a password set by

the user for the database and then when

you want to log into your SQL Server you

have to mention those username and

passwords so Guys these were two

authentication modes that is the windows

mode and the mixed mode now let's move

forward with the next question that is

mentioned the differences between local

and Global temporary tables now the

local tables are basically those tables

which only exist for the duration of the

connection or the duration of the that

particular statement which is executing

but when it comes to Global temporary

tables the global temporary tables exist

permanently in the databases and only

the rows get deleted when the connection

gets closed right so over here you have

to remember that you know the structure

does not get deleted only the rows get

deleted so if you have to talk about the

syntax between both of them then I would


say the local temporary variable you can

write a syntax as you know create table

and then put a hash mark and mention the

table name coming to Global temporary

tables the only difference in syntax is

that you know you have to mention two

hashes so you'll mentioned create table

hash and then again in hash and then

you'll mention the table name so Guys

these were the differences between local

temporary table and Global temporary

table now let's move forward with the

next question that is how can you check

the version of SQL Server now I would

say you could be asked this question

just to check whether you have a good

hand on the commands or not so to check

the version of SQL Server you just have

to mention the command that you can see

on my screen that is Select and then add

the rate at the rate version now this

particular command will basically give

you the version of the SQL Server that's

installed onto your system and this

gives an output as one n wire cache

string now let's move forward with the

next question that is what is single

user mode and what are the steps you

should follow to start SQL server in a


single user mode now as the name

suggests the single user mode this

particular mode is basically used when

you only want a single user to be active

on your SQL Server so single user mode

is a mode where only single user

connects to the server now you might be

wondering when do we use it right now

let me tell you that you know it may

often happen that you would want to

start an instance of a SQL server in the

single user mode and you would want to

do this either when you want to recover

the data from other database system or

maybe you want to change the server

configurations so basically there are

two scenarios where you would want to

use the single user mode that is either

you want to recover data from the other

database system or you would want to

change the server configurations so when

you start the SQL server in single user

mode then any member of the the

computer's local administrators group

gets connected to the instance of SQL

Server as the system admin now once you

start the SQL server in a single user

mode what happens is that you know a

single user connects to the server and

the checkpoint process is not executed


since it is executed by default at the

starter also note that you know you have

to stop the SQL Server agent service

before connecting to an instance of the

SQL server in the single user mode now

this is a little bit of an extra

information that you can give to an

interviewer but I would say it would be

nice if you answer like that now to

start the SQL server in single user mode

you basically have to use the command of

SQL command hyphen M right so you just

type in SQL CMD hyphen M and then you

can start the SQL server in the single

user mode now to connect through a query

editor in the management Studio use you

can just mention hyphen M and then you

can mention the Microsoft SQL Server

management Studio query that query is

completely on your basis that how you

want to connect but these are the two

ways through which you can start the SQL

server in a single user mode so guys

that was about this question now let's

move forward with the next question that

is what is the SQL Server profiler the

Microsoft SQL Server profiler is an

interface used to create and manage

traces so basically what it does is that


you know it analyzes and replace the

trace results so here the events are

saved in a trace file which are later

analyzed or are used to replay a

specific series of steps while debugging

an issue now you can use the SQL Server

profile it for activities as you can see

on my screen like you know finding the

root cause of the problem monitoring the

performance of SQL Server to handle

workloads diagnizing the slow queries

capturing a series of SQL statements

causing a problem to further replicate

the problem on the test server while

debugging the issue and also correlate

the performance counters to debug the

issues easily so guys this was about SQL

Server profiler now let's move forward

with the next question that is what is a

TCP port on which SQL Server runs now

this is one of the most interesting

question that is asked in Intel the real

status because you know it's a number

that you have to guess exactly and then

your answer cannot be wrong right so

well the answer to this particular

question is that you know the TCP IP

port on which SQL Server runs is 1433

right so that's 1433 that you have to

keep in your minds now let's move


forward with the next question that is

what are some queries in SQL server and

then can you mention few properties of

it so if I have to explain you what a

sub query is a sub query is a query

inside another query where a query is

defined to retrieve data or information

back from the database so in a sub query

the outer query is called the main query

whereas the inner query is called the

sub query sub queries are always

executed first and the result of the sub

query is passed to the main query now

sub queries can be nested inside a

select statement update statement or any

other query a sub query can also use

comparison operators like you know

greater than less than or equal to now

if you have to mention few properties of

sub queries then you can say that you

know it must be enclosed in parenthesis

as it must be executed first before the

main query more than one query can be

included and a sub query should not have

the order by Clause but can definitely

include the where group Y and the having

Clauses the sub query must be on the

right hand side of the comparison

operator of the main query and must


include a select clause and a from

Clause so Guys these are a few

properties of sub queries now let's move

forward with the next question that is

how do you start single user mode in

cluster installations now in clustered

installations the SQL Server basically

uses the dll available connections and

thus blocks any other connection to the

server now in this state if you try to

bring the SQL Server agent resources

online then it may fail the SQL

resources to a different node as it

could be configured to a group so to

start a single user mode in cluster

installations you have to follow the

steps that you can see on my screen you

have to first go to the advanced

properties and then remove the hyphen M

startup parameter after that you have to

put the SQL Server resource offline and

then issue the command from the command

prompt and make sure that you know you

are at the current owner node of the

group so the command is basically net

start Ms SQL Server slash m after that

you have to verify from the cluster

administrator or failover cluster

Management console that a SQL Server

resource is still offline or not and


then you have to connect the SQL Server

by using the command SQL CMD hyphen e

hyphen s and then do the required

operations once an operation is complete

you have to close the command prompt and

then bring back the SQL server and other

resources online through cluster

administrator so Guys these are few

steps that you have to follow to start

single user mode in cluster

installations

now moving on to the next question that

is what do you understand by replication

in SQL server and what are the different

types of replication that are present in

SQL Server now replication in Microsoft

SQL Server is a process to synchronize

the data across multiple servers now

this is generally done by the replica

set and these sets provide multiple

copies of data with redundancy and high

availability on different servers not

only this but replication also provides

a mechanism to recover from the failures

so it basically removes the dependencies

from single server to protect the loss

of data from that particular server now

the different types of replication

available in SQL Server are merge


replication transactional replication

and snapshot replication now the merge

replication basically groups the data

from various sources to a single

centralized database and is used in the

server to the client information coming

to transactional replication this

particular application is basically a

process of Distributing data from

publisher to subscriber and is used in

the server-to-server environments moving

on to the final replication that is a

snapshot replication the snapshot

replication basically distributes data

exactly as it appears at a specific

moment and is used for replicating data

which changes infrequently so guys that

was about replication and its type now

let's move forward with the next

question that is what are the

differences between Microsoft SQL server

and Oracle now if you have to mention

the differences between Microsoft SQL

server and Oracle then Ms SQL Server

basically provides simple and easy

syntax whereas Oracle consists of

complex and comparatively more efficient

syntaxes the MS SQL Server uses

basically the transact SQL or the D SQL

whereas Oracle uses the pl SQL moving on


to the next difference that is you know

SQL Server does not support query

optimization but Oracle supports query

optimization and uses the star query

optimization

moving on to the next difference in SQL

Server rollbacks are not allowed in the

transaction processes but in Oracle

rollbacks are definitely allowed during

the transaction processes SQL Server

allows incremental partial and full

backups whereas Oracle allows

incremental full file level and

differential backups SQL Server does not

support clustering whereas Oracle offers

support for clustered configurations in

SQL Server statements such as insert

update delete are executed serially

whereas in Oracle statements such as

insert update delete and merge are

executed parallely and finally coming to

the last difference jobs are scheduled

via the SQL Server agent and SQL Server

whereas jobs are scheduled via the

Oracle scheduler or the OEM in the

Oracle so Guys these were few

differences between SQL server and

Oracle so as I said before you can also

talk about your personal experience


while using both of them now let's move

forward with the next question that is

what do you understand by intent logs

now Microsoft SQL Server uses a lock

hierarchy whenever the data is read or

something is changed in the data so

whenever a row is read the SQL Server

acquires a shared log and whenever you

change a row the SQL Server acquires an

exclusive log so these logs are

basically incompatible with each other

and this is where the intent logs come

into the picture so the intent logs are

basically used to indicate at a higher

level which logs are applied within a

lock hierarchy now there are mainly

three kinds of intense logs that is the

intent shared log the intent update log

and the intent exclusive log now as the

name suggests the intent shared log is

basically used when you have a shared

block at the row level coming to intent

update lock the intent update lock is

used when you have an update lock at the

row level and finally coming to intent

exclusive lock this particular lock is

used when you have an exclusive lock at

the row level now let's move forward

with the next question that is what are

the steps you must follow to hide SQL


Server instances now the steps that you

must follow to hide SQL Server instances

are as you can see on my screen

initially you have to open the SQL

Server configuration manager and then

you have to go to the SQL Server network

configuration after that in the SQL

Server network configuration go to

protocols and choose the instance of the

SQL Server later on you just have to

right click on the instance and select

the properties after that you'll see a

dialog box which opens up so go to the

flags tab in that particular dialog box

and then you see an option of hide

instance over there so over there you

just have to go to that particular

option of hide instance and just say yes

and then open the drop down and choose

yes so once you choose yes you just have

to finally click on OK and then

automatically your instance will be

hidden so Guys these were the steps to

hide the instance in SQL Server next in

this tutorial on SQL Server let's move

forward with the next question that is

what do you understand by data quality

services in SQL Server so the data

quality services in SQL servers is


basically a knowledge driven data

quality product right so the SQL Server

data quality services enable the user to

build a knowledge base and thereafter

use it to perform tasks such as

correction deduplication enrichment and

standardization of data apart from this

the data quality services also provide

profiling and enable you to perform data

cleaning with help of cloud-based data

services now the dqs services or the

data quality services basically consists

of two component statistic data quality

server and the data quality client now

talking about the server first so the

data quality server is basically a SQL

Server instance feature consisting of

three SQL Server catalogs with data

quality functionality and storage coming

to data quality client it is also a SQL

Server feature which users can use to

perform computer assisted data quality

analysis and manage the data quality

interactively right so guys that was

about the data quality services now

let's move forward with the next

question that is explain magic tables in

SQL Server now magic tables are tables

which are automatically created in SQL

server and are used to internally store


the inserted updated values for DML

operations such as select delete insert

update and so on right so basically guys

magic tables are just automatically

created tables inside equal server used

to basically store values you know maybe

inserted updated or deleted and you can

understand that you know magic tables

are used on a temporary basis now let's

move forward with the next question that

is what do you understand by change data

capture so change data capture or most

commonly known as CDC is used to record

insert update delete activities applied

on the tables so as the name suggests

the change data capture is used to

capture the data that has been changed

recently so the column information and

the metadata required to apply the

changes to the Target information are

captured for the modified rows and are

eventually stored in the change tables

so these change tables are the mirror

images of the original column structure

so guys that was about change data

structure now let's move forward with

the next question that is what do you

understand by triggers and mention the

different types of it so if you have to


explain triggers then triggers are used

to execute batches of SQL code whenever

insert delete or update commands are

executed against the table so basically

triggers are automatically executed

whenever the data is modified based on

the data manipulation operations or you

can just understand that you know

triggers are triggered when there's an

event happening so the different types

of triggers are basically insert update

delete and installed off so guys that

was about triggers now let's move

forward with the next question that is

what do you understand by recursive

stored procedures so recursive stored

procedure is basically a problem solving

method through which you can arrive at

the solution again and again and again

right so in programming also we see

recursive functions right so you can

just keep calling back the function and

with the help of that you can keep

getting solution again and again and

again right so that's the same in SQL

also recursive stored procedures is

basically a method through which you can

arrive at the solution again and again

so that was about recursive stored

procedures guys let's move forward with


the next question that is explain log

shipping and it's advantages Now log

shipping is basically the process of

automation of backup to restore

databases from one Standalone server to

another Standalone standby server so you

can understand log shipping as one of

those Disaster Recovery Solutions as it

makes sure that you know even if one

server fails the standby server will

have the same data as that of the server

itself so the advantages of log shipping

are as you can see in my screen it needs

low maintenance and it's easy to set up

the secondary database created is used

for read-only purposes only and you can

also create multiple secondary standby

servers not only this but it also allows

a delay specified by the user for the

time between the primary servers backup

the log of the primary database and when

the secondary servers restore or apply

the log backer so Guys these were few

advantages of log shipping now let's

move forward with the next question that

is what are Trace flags and mention a

few common Trace flags that you might

have faced so the trace flags are

basically those flags which are used to


alter server behaviors or set server

characteristics

now few common Trace flags that all of

us use or encounter basically one two

zero four one two zero five one Triple

Two so all the three of them I've used

for deadlock information the 174 craze

flag is used to increase the SQL Server

database engine plan cache bucket count

from 40 0009 to 1 lakh sixty thousand

one on 64-bit systems coming to Triple

one eight so triple one eight Forces

uniform extant allocations instead of

mixed page allocations moving on to the

next one that is 652 now 652 is

basically used to disable the page

prefetching scans and 2566 is used to

basically run the dbcc check DB command

without the data Purity check unless the

data Purity option is specified

so Guys these are few Trace flags that

I've encountered or I've used now this

answer is not something that you know

you have to give only these phrase Flags

there are hundreds of Trace Flags

present so whatever you have encountered

or maybe whatever you have used you can

mention that right now let's move

forward with the next one that is

mentioned the differences between


substring and character index in SQL

Server substring is basically used to

return a specific portion of the string

in a given string but whereas the

character index is used to return a

character position in a given specified

string right so for example if you have

substring at Eureka one comma four so

what the syntax mentioned is that you

know edureka is our string one is a

starting value from where the characters

have to be extracted and four is the

range still where the characters have to

be extracted so if you count edirect on

your fingers we have seven letters right

so we've mentioned one to four so our

output should be e d u r right so it

starts with e that's the first letter

then D second one U third one and our

fourth one but when it comes to

character index character index as I

mentioned before is used to return a

character position in the given string

right so for example if you mention an

example character index R comma idea

comma 1 R is basically the character for

which we want to find out the position

it requires a string and one is the

starting range of the string so if you


again count edirect on your fingers then

you see R is at the fourth position so

we see output as four so Guys these were

the differences between some string and

character index in SQL Server now let's

move forward with the next question that

is what do you understand by analysis

services in SQL Server so analysis

services in Microsoft SQL Server is an

analytical data engine used in business

analytics and decision support so the

service basically provides Enterprise

grade semantic models for client

applications and reports such as power

bi Microsoft Excel and other

visualization tools so the analysis

Services is basically available in

platforms like you know Azure analysis

Services power bi premium and SQL Server

analysis services so guys that was about

analysis services in SQL Server now

let's move forward with the next

question that is what do you understand

by mirroring and mention few advantages

of it so mirroring in SQL Server is

basically designed to maintain a hot

standby server that is consistent with

the primary server in terms of the

transaction also the transaction log

records are sent from the principal


server to the secondary server now the

advantages of mirroring are as you can

see on my screen it consists of an

automatic failover mechanism it is more

efficient than the lock shipping and is

more robust and the primary server is

synced with a secondary server in real

time

so guys that was about mirroring now

let's move forward with the next

question that is when do you think a

developer should use SQL server-based

curses so SQL Server based cursors are

used when you wish to work on a record

at an instance of time rather than

taking all the data from a table as a

bulk however cursors are not preferred

to be used when large volumes of data is

present as it affects the performance so

in a scenario where it is not possible

to avoid the curses then I would suggest

try to reduce the number of Records to

process by using a temporary table and

then eventually build the cursor from

this so I think guys this is one of the

most practical questions that could be

asked where the interview checks whether

you have practical knowledge of where

SQL can be used and how you can use


different commands or different

functionalities based on the scenarios

now let's move forward with the next

question that is what part of database

design do you think affects the

performance of a SQL Server based

application well I would say the

physical and The Logical design plays an

important role in the performance of SQL

Server based applications and we need to

ensure that the correct data is captured

in the proper table the data items have

proper relationships between them and

the data redundancy is reduced I would

also suggest that you know while you're

designing a database make sure that it

is an iterative process to achieve all

the required system goals and is then

the constant observation to make sure

you know all the client requirements are

added and the database satisfies the

requirement now I'm saying this because

you know once the database design is set

it's very tough to change the database

design according to the requirements

that come later on so you cannot change

the basic entities of the databases but

you can only add new relationships and

data items so I would say if something

affects the performance of a SQL Server


based application then I would say the

physical and The Logical design of the

database affects the most now let's move

forward with the next question that is

what do you understand by user defined

functions in SQL server and then what

are the steps to create and execute the

user defined function in a SQL Server

well a user defined function as the name

suggests is a function written as per

the needs of the user by implementing a

specific logic now in these kinds of

function the user is not limited to any

predefined functions and simplifies the

complex code of a predefined function by

writing a simple code apart from this

let me also tell you that you know the

user defined function returns a scalar

value or a table now to create a user

defined function you can refer to the

example that you can see on my screen

I've just created a function sample func

and then in the brackets I've put

azureate num end so basically it's an

integer and then it returns a table as

return select star from customers where

customer ID equal to as right now right

we're trying to basically written all

the customer IDs from our customer table


and store it in a table now after that

to execute the function that we had just

created you just have to mention the

command Select Staff from sample func

that is basically the function's name

and in Brackets you'll mention the

customer ID so for example I've

mentioned 10 over here so that's how

guys you can create a user defined

function and also execute it now let's

move forward with the next question that

is how can you ensure that the database

and SQL Server based applications

perform well well I would say to ensure

that the database and the SQL Server

based applications perform well a

developer must check the types of

information stored the volumes of data

and what data will be accessed so in a

scenario where you're upgrading an

existing system you should analyze the

present data the existing data volumes

occur and then check the method through

which the data is accessed to help you

understand the problem areas for the

design but on the other hand if you're

creating a new system then you have to

keep the information about what data

will be captured what are the

constituents of data and the


relationship between the data items so

like that the developer can make sure

that you know the database and SQL

Server based applications can perform

well now let's move forward with the

next question that is what are

relationships in databases and what are

the different types of it well I would

say a relationship in database

management system is a scenario where

two entities are related to each other

so basically if you have two tables

table a and table B then the table

consisting of the foreign key references

to that of the primary key of the other

table so the different types of

relationships in dbms or database

management systems are one-to-one

relationship one-to-many relationship

many to many relationship and

self-referencing relationship coming to

one-to-one relationship so this is

basically used when a single Row in

table a is related to single row and

table B coming to one to many

relationship this is used when a single

rowing table is is related to many rows

in table B coming to many to many

relationship this is used when you have


many rows in table a related to many

rows in table B and finally coming to

self-referencing relationship this is

used when a record in table a is related

to the same table itself

now let's move forward with the next

question that is what are joints in SQL

and what are the different types of

joints a joint Clause is basically used

to combine rows from two or more tables

based on a related column between them

and it is used to merge two tables or

retrieve data from there so there are

mainly four types of joins in SQL the

inner joint the right join the left join

and the full joint right so I'm now

going to go into depth of them so if you

want to know how to use SQL joins you

can refer to my session on SQL joins on

that node let's move forward with the

session and let's look into the next

question that is what is the command

dbcc check DB used for

so the command dbcc check Devi is used

to basically check the physical and The

Logical Integrity of all the objects in

the mentioned database so to do that it

basically performs the operations that

you can see on my screen it runs the

dpcc check a log on Dimension database


and on every table and view in the

database the tvcc check table command is

executed it also runs the dbcc check

catalog on the database and then it

validates the contents of every index

view in the mentioned database after

that it also validates the link level

consistency between file system

directories and table metadata while

storing via binary Max data in the file

system using file stream

finally it validates the service broker

data in the database so if You observe

clearly you just have to execute the

dbcc check DB command and automatically

the tbcc check unlock the check table

and the check catalog command gets

executed also note that dbcc is

supported on databases that contain

memory optimized tables but does not

provide repair operations so basically

this implies that you must regularly

backup databases and test those backups

so guys that was about the dvcc check TB

command now let's move forward with the

next question that is what do you

understand by check constraint in SQL

Server so the check constraint in SQL

Server is basically used to limit the


values or the type of data stored in a

column now once you apply the check

constraint on a single column you can go

forward and apply specific values for

that particular column see the example

on my screen I've created a table

customers with few columns like customer

ID first name age and City and then I've

applied the check constraint and then

I've given the name to be check

underscore customer and the condition

that I've applied is basically eight

should be greater than 20 and City

should be Hyderabad so guys that is

basically how you can use the check

constraint now let's move forward with

the next question that is what do you

understand by coil is in SQL Server now

the coolest function is used to

basically return the first normal

expression within the arguments so the

coolest command is basically used to

return a non-null value from more than a

single column in arguments

so to use the coils command you can

refer to the example that you can see on

my screen that is Select coales and then

I've mentioned customer ID customer name

amount from customers right so basically

customers was a table and customer ID


customer name amount are basically a

column names right so I'm basically

trying to return the first normal

expressions from customer ID customer

name and amounts

now let's move forward with the next

question that is explain the usage of

floor function in SQL Server now the

flower function is used to round up a

non-integer value to the previous least

integer value this function returns a

unique value after rounding of the

digits now the syntax is as you can see

on my screen it's basically floor and

then you mentioned the expression and if

you also want to know how to use it you

can see the example on my screen I've

just mentioned floor and then I've

mentioned in bracket 7.3 so it will

basically round off the value to 7. so

guys that was about the floor function

now let's move forward with the next

question that is what is the command

used to check logs in Microsoft SQL

Server so to check logs in a database

you have to use an inbuilt stored

procedure that is sp underscore log

so the syntax is again as you can see on

my screen it's SP log and then you


mentioned azureate svid equal to 1 and

session id1 you can go forward and

mention the session id2 and so on right

you can also go forward and explain the

command to the interviewer by giving

them an example right so for example if

you want to list all the logs currently

held in an instance of a database engine

you can use the command SP underscore

lock as you can see on my screen I've

mentioned use sample database that is

basically my database name and then I've

mentioned go execute SP underscore log

and then go again over there so that is

basically how I want to list all the

logs currently held in an instance of

the database engine

now let's move forward with the next

question that is mentioned the three

ways to get a count on the number of

Records in a table now the three ways

through which you can get a count of the

number of Records in a table or as you

can see on my screen you can initially

write a query like you know Select Staff

from table name this will basically

retrieve all the data from the table

right so and over there you can clearly

get a count of the number of Records in

the table the second way is basically


you use the count function right so for

that you'll write a query like as you

can see on the screen that is Select

count and in Brackets you'll mentioned

star from table name right so you'll

basically count all the row values and

then you'll mention and the third one is

basically select rows from indexes where

ID equal to object underscore ID you

mentioned the table name and index ID is

less than two right so Guys these are

the three ways through which you can get

a count of the number of Records in a

table now let's move forward with the

next question that is what is the usage

of the sine function now the sine

function is basically used to determine

whether the mention number is 0 positive

or negative so it will either return 0

plus 1 or minus this one so the syntax

is as you can see on my screen is just

sign and in Brackets you mentioned the

number and if you want to see the

example the example is again on my

screen like you know if you mention sign

0 then it will return 0 if you mention

sign let's say 21 then it will return 1

and if you mention sign let's say minus

21 it will return minus 1. so guys that


was about the sine function now let's

move forward with the next question that

is write a SQL query to find the first

weekday of the month

now to find the first weekday of the

month you can write a query like as you

can see on my screen that is Select date

name and in Brackets you'll mention the

W comma date add in the brackets again

you'll mention DD comma date part and

then in Brackets again we'll mention DD

comma get date that is basically used to

get the current date plus one common get

did as first a right so that's how you

basically get the weekday of the month

now days add date part get dates are all

predefined functions that you can use

now let's move forward with the next

question that is mentioned the command

used to rename the database now the

command used to rename the database is

sp underscore rename DB so to know how

to use this command you can look at my

screen you basically have to mention SP

underscore rename DB and then you have

to mention the old database name and

then the new database name so for

example if you have customers initially

and then you want to change it to

customers information you mentioned SV


underscore rename DB customers and then

customer information so that's how guys

you can rename the database now let's

move forward with the next question that

is write a query to find the fifth

highest amount paid from the customers

table now to find the fifth highest

amount rate from the customers table you

can write a query as you can see on my

screen that is select top one amount

from and then in a brackets you'll

mention select distinct top 5 amount

from customers order by amount in a

descending order and then close the

inner brackets and then come out of the

brackets and mention order by amount so

basically in a query we're basically

trying to find out the top five distinct

amounts where by the customers in the

customer table and then we'll order it

by descending order and when the output

comes to the main query or the outer

query in the outer query it is ordered

by the amount and then it is in the

descending order already so you just

pick up the first amount

so guys that's how you can write a query

to find the fifth highest amount paid

from the customers table now let's move


forward with the next question and

understand how can we delete a table in

SQL Server well to delete the table in

SQL Server you basically have to use the

delete command so the syntax is as you

can see on my screen you just mentioned

delete and the table name so for example

if you have to delete the customer's

table then you mentioned delete

customers so guys that was about how you

can delete a table in SQL Server now

let's move forward with the next

question that is what is the purpose of

update statistics and scope identity

function the update statistics function

is basically used to update the

information used by the indexes such as

the distribution of key values for one

or more statistics groups is mentioned

in the index view or the table coming to

scope identity function the scope

identity function is used to create

identity values for tables in the

current execution scope now let's move

forward with the next question that is

what do you understand by physical only

option in dvcc check DB command well the

physical only option is used to limit

the checking to the Integrity or

physical structure of the record headers


page and also the allocation consistency

of the database the physical only check

is used to provide a small overhead

check of the physical consistency of the

database and this option also causes a

shorter runtime for dbcc check DB on

large databases so it's generally

recommended for frequent use on

Productions systems now let's move

forward with the next question that is

can you explain how long are the locks

retained with repeatable read and

serializable isolation levels during a

read operation with low level locking

well with repeatable read and

serializable isolation levels the locks

are held during the transaction answer

to this particular question is that you

know the locks are held during the

transaction but if you consider the read

committed then the locks are held for

the isolation level

so guys that was about this question now

let's move forward with the next

question that is mentioned the

differences between having and where

Clause well the having Clause is

basically used only with the select

statement whereas the where Clause is


used in a group by Clause the having

Clause is used with a group by function

in a query whereas the where Clause is

applied to each row before they are a

part of the group by function in a query

also note that you know whenever Group

by function is not used having behaves

like a where Clause right so Guys these

were the differences between having and

where Clauses now let's move forward

with the next question that is what do

you understand by integration services

in SQL Server well integration Services

is a platform offered by Microsoft to

build Enterprise level data

transformation Solutions and integration

now this Services solve complex versus

problems by loading data warehouses

perform data wrangling copy or download

files and manage SQL Server objects also

integration Services can extract and

transform data from a wide variety of

sources such as relational data sources

XML data files load the data into more

than a single database so basically you

can use the integration services to

create Solutions without coding or maybe

core complex tasks program the extensive

integration object model to create

objects not only this but the


integration Services include a good set

of built-in tasks and Transformations

and graphical tools used for building

packages and also contain the catalog

database to store run and manage

packages

so guys that was about integration

services in SQL Server now let's move

forward with the next question that is

what do you understand by hot fixes and

patches in SQL Server so hot fixes are

single cumulative software packages

applied to live systems so basically

this includes one or more files used to

address a problem in a software product

the patches are a program installed on

the machines to rectify the problem

occurred in the system and ensure the

security of that particular system

so basically hot fixes are a kind of

patch offered by Microsoft SQL Server to

address specific issues now let's move

forward with the next question that is

can you name a few encryption mechanisms

in SQL Server well few encryption

mechanisms in SQL Server to encrypt the

data and database are as you can see on

my screen that is transparent data

encryption symmetric case asymmetric


Keys transact SQL functions add

certificates right so these are few

encryption mechanisms through which you

can protect your data you can encrypt

the data in a database

now let's move forward with the next

question that is what are the options

which was may send to allow the usage of

optimistic models well the options that

must be said to allow the usage of

optimistic models are the rate

underscore committed underscore snapshot

option and allow underscore snapshot

underscore isolation option right so

basically these two options are used

that is the read committed snapshot and

the allow snapshot isolation option

so the read committed snapshot option is

basically used to read the committed

optimistic model and the allow snapshot

isolation is used for the snapshot

isolation levels right so Guys these are

the two options that you must keep in

mind now let's move forward with the

final question for this particular

session that is what are the common

performance issues in SQL Server now

this is one of the most practical

questions I would say that could be

asked because you know it's completely


on your experience basis on how much you

have used the databases and how many

issues that you have faced so the most

common performance issues in SQL Server

are fragmentation input output bottom

next blocking queues Deadlocks and

unused indexes so these are few common

performance issues that I had seen But

if you think you've also seen any other

issues you can definitely go forward and

mention it so I would say in this

particular question also please explain

with examples on which scenarios did you

see the performance issues and how did

you resolve it so on that note guys we

come to an end to this particular

session I hope you found this session

interesting and informative so thank you

and have a great day I hope you have

enjoyed listening to this video please

be kind enough to like it and you can

comment any of your doubts and queries

and we will reply them at the earliest

do look out for more videos in our

playlist And subscribe to edureka

channel to learn more happy learning

You might also like