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

softcopy of dbms

The document provides an overview of MySQL, covering its basic concepts, types of database management systems (DBMS), and various SQL operations including Data Manipulation Language (DML) and Data Definition Language (DDL) commands. It details the creation of databases and tables, the implementation of constraints, and the use of operators for data retrieval and filtering. Additionally, it discusses built-in functions in MySQL for data manipulation, ensuring data integrity, uniqueness, and relationships between tables.

Uploaded by

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

softcopy of dbms

The document provides an overview of MySQL, covering its basic concepts, types of database management systems (DBMS), and various SQL operations including Data Manipulation Language (DML) and Data Definition Language (DDL) commands. It details the creation of databases and tables, the implementation of constraints, and the use of operators for data retrieval and filtering. Additionally, it discusses built-in functions in MySQL for data manipulation, ensuring data integrity, uniqueness, and relationships between tables.

Uploaded by

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

TASK-0

DATE:
AIM::To understand the basics of mysql
DATA: Data refers to collection of facts, figures, and information that is stored, managed, and
retrieved using the DBMS software. Data in a DBMS is organized in a structured manner to
facilitate efficient access and manipulation.

INFORMATION: Information refers to the processed and organized data that is meaningful
to the users.

DATABASE: A data base is a collection of related data. Database is the place where data gets
stored and the retrieval time is fast.

WHAT IS DBMS?

A database management system (DBMS) is a computerized system that enables users to


create and maintain a database.

TYPES OF DBMS:

There are different type of DBMS. They are given below.


1.N-DBMS

2.H-DBMS

3.R-DBMS

4.OO-DBMS

5.OR DBMS

• N-DBMS: Network DBMS


The N-DBMS works like linked list. If one node is deleted then the entire
structure will be disturbed. Because of this N-DBMS is not preferable.
• H-DBMS: Hierarchical DBMS.
The H-DBMS works like trees in Data structure. If one node from the tree
isdeleted then the entire structure will disturbed. Because of this H-DBMS is
not preferable.
• R-DBMS: Rational DBMS
The R-DBMS will have rows and columns. If one row is deleted or effected
then there will be no effect on the structure, so R-DBMS is preferable.

• OO-DBMS: Object oriented DBMS.


Object-Oriented Database Management Systems (OODBMS or
ODBMS) are designed to handle data as objects, similar to object-oriented
programming. This approach integrates the database capabilities with the
object-oriented programming language.
• OR-DBMS:Object relational DBMS
Object-Relational Database Management Systems (OR-DBMS)
combine features from both relational databases (RDBMS) and object-
oriented databases (OODBMS). They aim to bridge the gap between
relational databases, which are excellent at handling structured data,
and object-oriented databases, which excel at managing complex data
types and relationships.

SOFTWARE FOR DBMS:


1. MySQL: A free, open-source relational database management system. It's widely
used for web applications.
2. Microsoft SQL Server: A commercial relational database management system
developed by Microsoft, used for a wide range of data management tasks.
3. Oracle Database: A commercial, multi-model database management system known
for its performance and scalability.
4. IBM DB2: A commercial relational database management system known for its data
warehousing capabilities.
5. MongoDB: A popular NoSQL database designed for handling large volumes of
unstructured data.
6. MariaDB: A community-developed fork of MySQL, known for its performance and
reliability.

Result : Successfully understand the basic concepts of dbms


TASK-1
DATE:

AIM::To understand the creation of databases and tables in SQL, perform Data
Manipulation Language (DML) operations like INSERT, UPDATE, DELETE,
and SELECT, and explore Data Definition Language (DDL) commands like
ALTER, DROP, TRUNCATE

1.CREATING DATABASE::

➢ It creates a database with is given name.


➢ SYNTAX: create database database_name;
2.SHOWING ALL THE DATABASES.

➢ It shows all the database that are present in the mysql nutshell.
➢ SYNTAX: show databases;

3.USING A DATABASE TO STORE THE VALUES.

➢ All the information will be stored in the given database.


➢ SYNTAX: USE database_name;
4.CREATING A TABLE FOR THE STORING OF THE DATA.
• The table store’s the data in the rows and columns ;
• The rows in the table is called "tuple" or "record"
• The columns in the table is called "field names" or "attributes".

➢ SYNTAX: CREATE TABLE table_name (


column1 datatype [constraints],
column2 datatype [constraints],
column3 datatype [constraints],
...
);
➢ Given information will be stored in the created table.
5.SHOWING THE CREATED TABLE.
➢ Shows the structure of the created table.
➢ SYNTAX: DESCRIBE table_name(or)DESC table_name;

6.DATA MANIPULATION LANGUAGE. (DML)


INSERT – Adds new records (rows) to a table.
UPDATE – Modifies existing records in a table.
DELETE – Removes records from a table.
SELECT – Retrieves data from one or more tables.
• INSERTING

➢ Used to insert the data into the table;


➢ SYNTAX: INSERT INTO table_name (column1, column2,
column3, ...)
VALUES (value1, value2, value3, ...);
• DISPLAYING THE TABLE.

➢ Display the data in the table


➢ SYNTAX: SELECT * FROM table_name;
• UPDATING THE VALUES.

➢ Update the present values that are present in the table


➢ SYNTAX: UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

• DELETE THE VALUES.


➢ Delete the present column in the table
➢ SYNTAX: DELETE FROM table_name
WHERE condition;
• AFTER THE DELETION THE TABLE IS:

7.Data Definition Language. (DDL)


• ALTER(ADD)

➢ Used to add a column into the table


➢ SYNTAX: ALTER TABLE table_name
ADD datatype [constraint];
• ALTER(DROP).

**AFTER DELETION A COLUMN IN THE TABLE:

➢ Used to drop the column in the table


➢ SYNTAX: ALTER table table_name drop column column_name;
• ALTER(MODIFY)

➢ Change the datatype of the column.


➢ SYNTAX: ALTER TABLE table_name
MODIFY COLUMN column_name datatype(size);

• TRUNCUATE

➢ Delete the data from the table and the structure of the table
remans same and the table will be empty
➢ SYNTAX: TRUNCATE tabletable_name;

• DROP

➢ Drop will delete the table from the database when we want to
display it shows the error
➢ SYNTAX: DROP table table_name;

RESULT:

Successfully created a database and tables, performed Data Manipulation


Language (DML) operations such as INSERT, UPDATE, DELETE, and
SELECT, and executed Data Definition Language (DDL) commands like
ALTER, DROP, and TRUNCATE. The database modifications and retrievals
were verified using appropriate SQL queries.
TASK-2
DATE:

AIM:: To implement and understand different constraints in SQL, including:


• Primary Key (Ensures unique and non-null values)
• Foreign Key (Establishes relationships between tables)
• Not Null (Prevents null values in a column)
• Unique (Ensures no duplicate values in a column)
• Default (Assigns a default value to a column if no value is provided)
• Composite Primary Key (Ensures uniqueness using multiple columns)

::CREATING DATABASE.

➢ It creates a database with is given name.


➢ SYNTAX: create database database_name;
::SHOWING ALL THE DATABASES::
➢ It shows all the database that are present in the mysql nutshell.
➢ SYNTAX: show databases;
::USING A DATABASE TO STORE THE VALUES.::

➢ All the information will be stored in the given database.


➢ SYNTAX: USE database_name;
::CREATING A TABLE FOR THE STORING OF THE DATA::
• The table store’s the data in the rows and columns ;
• The rows in the table is called "tuple" or "record"
• The columns in the table is called "field names" or "attributes".

➢ SYNTAX: CREATE TABLE table_name (


column1 datatype [constraints],
column2 datatype [constraints],
column3 datatype [constraints],
...
);
➢ Given information will be stored in the created table.
::SHOWING THE CREATED TABLE::

➢ Shows the structure of the created table.


➢ SYNTAX: DESCRIBE table_name(or)DESC table_name;
**INSERTING

**DISPLAYING THE TABLE.


➢ Display the data in the table
➢ SYNTAX: SELECT * FROM table_name;
**PRIMARY KEY

➢ Making an column as primary key constraint:


The particular is set to be as a primary constraint which ensures
that column doesn’t contains null and duplicate values.

➢ SYNTAX:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name PRIMARY KEY
(column_name);

**Inserting the values:


➢ Inserting the values for all columns as a row.

--Use of primary constraint:


➢ In case of adding a duplicate value the error should be generated
for the primary key constraint column.

**Making an column as not null constraint:


➢ It is used to not insert any null value for that column.

➢ SYNTAX:
ALTER TABLE table_name
MODIFY column_name datatype NOT NULL;
--Use of not null constraint:
➢ When the null values insert into the not null column the error
should be generated.

**Displaying the table:


➢ It is displaying the table.

**Making an column as unique constraint:


➢ The constraint applied to a column such that the column doesn’t
allow any duplicate values into it is called Unique Constraint.

➢ SYNTAX:
ALTER TABLEtable_name
ADD CONSTRAINTconstraint_nameUNIQUE(column_name);
--Use of unique constraint:
➢ It is not allowing duplicate values into the unique constraint
column.

--Creating an another table:


➢ It is used to creating an other table.
**Making an column as foreign key constraint:
➢ A foreign key is a field in one table that links to the primary key in
another table. It helps connect the two tables, ensuring that the data
in the foreign key matches an existing value in the other table. This
creates a relationship between the two tables.

--Use of foreign key constraint:

➢ the foreign key column takes values from only other column in
other table which has primary key constraint.

➢ SYNTAX:
ALTER TABLEtable_name
ADD CONSTRAINTconstraint_name
FOREIGN KEY (column_name) REFERENCESother_table
(referenced_column);
--Creating an column and make it as default constraint:
➢ The constraint applied to a column such that the column assigns a
default value to the row if now data is passed to that column is
called Default Constraint

--Use of default constraint :


➢ if you not give the values to that column it default shows some
value.

**Creating an table and in that make a composite primary constraint:


➢ A composite primary key is a primary key that consists of two or
more columns in a table, rather than just one. The combination of
these columns uniquely identifies each record (row) in the table.
Each individual column in a composite primary key might not be
unique by itself, but when combined, they ensure that every record
is distinct.

--Use of composite primary constraint :


➢ it is combination of two columns or more the duplicate has arises it
raise an error.
individual column in a composite primary key might not be unique
by itself, but when combined, they ensure that every record is
distinct.

➢ SYNTAX:
ALTER TABLE table_name
ADD CONSTRAINT constraint_name PRIMARY KEY (column1,
column2);
--Use of composite primary constraint :
➢ it is combination of two columns or more the duplicate has arises
it raise an error.

RESULT:
Successfully implemented and tested SQL constraints, ensuring data integrity,
uniqueness, and relationships between tables.
TASK-3
DATE:

AIM:: To understand and implement different types of operators in SQL for


data retrieval and filtering:

1. Relational Operators: =, !=, >, <, >=, <=


2. Logical Operators: AND, OR, NOT
3. Special Operators: IN, NOT IN, BETWEEN, LIKE

::OPERARTORS IN DBMS ::

➢ In the context of DBMS (Database Management System), an operator is a


symbol or keyword used to perform operations on data. Operators are
used in SQL to manipulate and compare data, perform calculations, or
control the flow of queries.
1.CREATION OF THE TABLE ;

2.DESCRIBE THE TABLE;


3.INSERTING THE VALUES INTO THE TABLE ;

.
4.DISPLAYING THE DETAILS OF THE TABLE ;

*************************OPERATORS***********************

❖ RELATIONAL OPERATOR:
Relational operators in DBMS are used to compare two values. They are
typically used in SQL queries to filter records based on certain conditions.
Types of Relational Operators:
1. =: Equal to
2. != or <>: Not equal to
3. >: Greater than
4. <: Less than
5. >=: Greater than or equal to
6. <=: Less than or equal to
These operators are used to compare columns with values or other columns in
SQL queries.
➢ SYNTAX :SELECT column_names
FROM table_name
WHERE column_namerelational_operatorvalue;
(i) Less than operator(<):

(ii) Greater than Operator(>):


(iii) Equals operator(=):

(iv) Not Equals(!=):

❖ LOGICAL OPERATIONS:
• Logical operators in DBMS are used to combine multiple
conditions in SQL queries. These operators return a boolean value
(TRUE, FALSE, or UNKNOWN) based on the evaluation of the
conditions.

(i).AND OPERATOR:

o Returns TRUE if both conditions are true.

➢ SYNTAX:
SELECT column_names
FROM table_name
WHERE condition1AND condition2;

(ii).OR OPERATOR:
o Returns TRUE if at least one of the conditions is true.

➢ SYNTAX:
SELECT column_names
FROM table_name
WHERE condition1OR condition2;

(iii).IN OPERATOR:

➢ SYNTAX:
SELECT column_names
FROM table_name
WHERE IN (VALUE1,VALUE2,..,);

(iv) NOT IN OPERATOR:

➢ SYNTAX:
SELECT column_names
FROM table_name
WHERE NOT IN (VALUE1,VALUE2,..,);

(V).BETWEEN OPERATOR:

➢ SYNTAX:
SELECT column_names
FROM table_name
WHERE BETWEENVALUE1 AND VALUE2;
(VI).LIKE OPERATOR:

➢ SYNTAX :
SELECT column_names
FROM table_name
WHERE column_name LIKE pattern;

➢ Displaying The Values If The Second Leter Is ‘A’.


➢ Displaying The Last Character Is The ‘Y’;

RESULT:: Successfully implemented and tested relational, logical, and special


operators in SQL for data retrieval and filtering. Queries executed correctly,
returning expected results.

TASK-4
DATE:
AIM:: to understand and implement different operations in mysql for data
updation.
BUILT-IN FUNCTIONS in MYSQL::
• We have created a table in the it2b database to perform the numeric
functions,stringfunctions,aggrgrate functions on the table.

❖ Numeric funtions:

1. ABS() (Absolute Value):

• Returns the absolute value of a number.(removes the negative sign if there is any).

➢ The ABS() function returns the absolute value of the number, meaning it removes the
negative sign, if there was one.
➢ Since all the s1_marks values are positive integers, the result will be the same as the
input.

2. ROUND()

➢ The ROUND() function rounds a number to the nearest integer (or specified decimal
places).
➢ Since the s1_marks values are decimal types, the result will be rounded to the nearest
integer.

3.CEIL() (Ceiling):

➢ Returns the smallest integer value that is >= to a number

➢ The CEIL() function returns the smallest integer greater than or equal to the given
number.
➢ The CEIL() function rounds the value up to the nearest whole number. Therefore, the
s1_marks values contain decimal values(91.20,94.50,85,60…..), the result will be the
smallest integer greater than or equal to each original value(92,95,86…)

5. FLOOR() (Floor):
➢ Returns the largest integer value that is <= to a number.

➢ The FLOOR() function returns the largest integer less than or equal to the given
number. As with the CEIL() function, since all values are greater or equal , here the
result now will be the values will be less or equal.
➢ The values of s2_marks like92.43,87.34,85,20…..will changed as 92,87,85,……..etc.

4. SQRT() (Square Root):

➢ The SQRT() function returns the square root of a given number. It’s used to calculate
the square root of each s1_marks value.
➢ The SQRT() function calculates the square root of each value in the s3_marks column.
For example, the square root of 85 is approximately 9.22.

6. POWER() (Exponentiation):

➢ The POWER() function raises a number to the power of another number. In this case,
the s1_marks values are squared (raised to the power of 2).

➢ The POWER() function squares each of the s1_marks values. For example, the square of
85 is 7225.

7. MOD() (Modulo):
➢ The MOD() function returns the remainder of the division of one number by another.
Here, we're finding the remainder when s1_marks is divided by 5.
➢ The MOD() function calculates the remainder when each value in s1_marks is divided
by 5. For example, 85 % 5 equals 0.
8. LOG() (Logarithm):

➢ The LOG() function returns the logarithm of a number to the base 10. This is useful
for data analysis, such as transforming values for certain types of visualizations or
calculations.
➢ The LOG() function computes the logarithm (base 10) of each value in the s1_marks
column. For instance, the log of 85 is approximately 1.929

9. TRUNCATE() (Truncation):

➢ The TRUNCATE() function truncates a number to a specified number of decimal


places. In this case, we are truncating s1_marks to 1 decimal place (though it doesn't
affect the integers).
➢ The TRUNCATE() function truncates the number to 1 decimal place. Since the values
are already integers, this operation simply adds a .0 to each value.
10. EXP() (Exponentiation):

➢ The EXP() function returns e (Euler’s number, approximately 2.718) raised to the
power of a given number. This is an important mathematical function that is used in
various fields of study, such as statistics, physics, and engineering.
➢ The EXP() function calculates e raised to the power of each value in s1_marks.
Since s1_marks are integers, this results in very large values. For
instance, EXP(85) results in approximately 1.52105E+37.

11. CONV() (Conversion Between Number Bases):

➢ The CONV() function in MySQL converts a number from one base to another. For
example, converting from decimal (base 10) to binary (base 2). We can convert
the s1_marks values into their binary representations.
➢ The CONV() function converts the decimal values of s1_marks into binary (base 2).
For example, 85 in decimal is 1010101 in binary.

10. EXP() (Exponentiation):


➢ The LN() function returns the natural logarithm of a number, which is the logarithm to
the base e. It is widely used in calculus and scientific calculations.

➢ The LN() function calculates the natural logarithm (logarithm base e) of each value in
s1_marks. For instance, the natural logarithm of 85 is approximately 4.442.

String funcions:
ASCII():

➢ The ASCII() function returns the ASCII value of the first character of a string.
➢ For example, if we applied ASCII(sname) to the sname column, it would return the
ASCII value of the first character of each student's name (e.g., ASCII('B') would
return 66 because 'B' is 66 in the ASCII table).

REVERSE():
➢ The REVERSE() function reverses the characters in a string. For example,
applying REVERSE(sname) on the sname column would transform the names like
"Aarav" into "nvaraA" or "Sara" into "araS", reversing the characters of each
name.
CHAR_LENGTH():

➢ CHAR_LENGTH(CHARACTER_LENGTH,LENGTH)-Returns the length of the


string(in characters)

➢ The CHAR_LENGTH() function returns the length of a string (number of


characters). If we applied CHAR_LENGTH(sname),
➢ it would return the number of characters in the student's name (e.g.,
CHAR_LENGTH('Aarav') would return 5).

UPPER(): (UCASE):

➢ Converts a string to upper-case.

➢ The UPPER() function converts all characters in a string to uppercase. For example,
applying UPPER(sname) would transform "Aarav" into "AARAV" or "Sara" into
"SARA", converting the entire name to uppercase.
SUBSTRING():(substr)

➢ Extracts a substring from a string (starting at any position)

➢ The SUBSTRING() function extracts a portion of a string.


➢ For example, SUBSTRING(sname, 1, 4) would extract the first 3 characters of the
sname column, so "Aarav" would become "Aara" or "Sara" would become "Sara".

CONCAT():
➢ Adds two or more expressions together.
➢ CONCAT_WS: Adds two or more expressions together with a separator.

➢ The CONCAT() function combines multiple strings into one.


➢ If we applied CONCAT(sir/madam, ' ', sname) on the sname columns, it would
concatenate the student's name and sir/madam string with it,
➢ e.g., “sir/madam Aarav”, “sir/madam Sara”.

REPLACE():

➢ Replaces all occurrences of a substring within a string, with a new substring


➢ The REPLACE() function replaces occurrences of a substring within a string.
➢ For example, applying REPLACE(sname, 'a', 'A') would replace all occurrences of 'a'
with 'A' in the sname column, transforming "Sara" into "SArA" , and ”Aarav” as
“AArAv”.

INSTR():

➢ Returns the position of the first occurrence of a string in another string

➢ The INSTR() function returns the position of the first occurrence of a substring in a
string.
➢ For example, INSTR(sname, 'a') would return the position of the first 'a' in the
student's name .
➢ (e.g., INSTR('Aarav', 'a') would return 1 because the'a' in "Aarav" is in first position).

LEFT():

➢ Extracts a number of characters from a string (starting from left).

➢ The LEFT() function extracts a specified number of characters from the left side of a
string.
➢ For example, LEFT(sname, 3) would return the first 2 characters of the name, so
"Aarav" would become "Aar" and "Sara" would become "Sar".

RIGHT():

➢ Extracts a number of characters from a string (starting from right).


➢ The RIGHT() function extracts a specified number of characters from the right side of
a string
➢ For example, RIGHT(sname, 3) would return the last 3 characters of the name, so
"Aarav" would become "rav" and "Sara" would become "ara".

FIELD():

➢ Returns the index position of a value in a list of values

➢ The FIELD() function returns the index position of a value in a list of values.
➢ For example, applying FIELD(department_id, 10,20,30,40,) would return the index
of the id’s in the list.
➢ If a student's department id is 30is , FIELD(department_id, 10,20,30,40,) would
return 3.

INSERT():
➢ Inserts a string within a string at the specified position and for a certain number of
characters.
➢ Syntax:INSERT(string, position, number, string2).
➢ The INSERT() function inserts a substring at a specified position within a string.
➢ For example, INSERT(sname, 2, 2, ‘XX') would insert 'XX' at position 3 in the
student's name.
➢ For "Rahul", this would result in "RXXul".

3.Date and time functions:


CURDATE():

➢ Returns the current date


➢ Also CURRENT_DATE()

➢ The CURDATE() function returns the current date (without time). For example,
CURDATE() can be used to calculate the number of days a student has been enrolled
since their joining_date by comparing CURDATE() with the joining_date column.

NOW():

➢ Returns the current date and time.

➢ Here we created another column ,that returning the current exact time and date of that
time,when we create the table and that instance.
➢ The NOW() function returns the current date and time. By applying NOW() with the
joining_date, you can get the exact duration between the time the student joined and
the current timestamp, which is useful for calculating the time elapsed in terms of
days, hours, or minutes.

DATE():

➢ The DATE() function extracts the date part of a datetime or timestamp.

➢ For instance, DATE(joining_date) will return just the date from the joining_date
column, excluding any time portion, helping to simplify date comparisons or
calculations.

DATEDIFF():

➢ The DATEDIFF() function calculates the difference in days between two dates.
➢ For example, DATEDIFF(CURDATE(), joining_date) will return the number of days
since a student joined,
➢ whereas DATEDIFF(date_of_birth, joining_date) will give the number of days
between their birthdate and joining date.

YEAR(), MONTH(), DAY():


➢ These functions extract the year, month, or day part of a date.
➢ For example, YEAR(joining_date) will return the year a student joined (e.g., 2023),
➢ MONTH(date_of_birth) will return the month of birth (e.g., 10 for October),
➢ and DAY(joining_date) will return the day of the month the student joined (e.g., 15).

TIMESTAMPDIFF():
➢ The TIMESTAMPDIFF() function calculates the difference between two dates based
on a specified unit (e.g., year, month, day, hour).
➢ For example, TIMESTAMPDIFF(YEAR, date_of_birth, CURDATE()) will return the
age of the student in years by comparing their birthdate with the current date.

STR_TO_DATE():

➢ The STR_TO_DATE() function converts a string into a date based on a given format.
For example, STR_TO_DATE('2025-02-02', '%Y-%m-%d') can be used to convert a
date string into a proper DATE format, and similarly, you could use this to convert
user input into a standard date format before storing it in the table.

3) Aggregrate functions:
SUM:

➢ The SUM() function returns the total sum of a numeric column.


SUM(s1marks): This will calculate the total of all marks in s1marks (subject 1) for all
students.

SUM(s2marks): This will calculate the total of all marks in s2marks (subject 2).

SUM(s3marks): This will calculate the total of all marks in s3marks (subject 3).
AS total_s1marks: We are using aliases (total_s1marks, total_s2marks, total_s3marks) to
give more readable names to the results.This output means that:

• The total marks obtained by all students in subject 1 (s1marks) is 585.

• The total marks obtained in subject 2 (s2marks) is 586.

• The total marks obtained in subject 3 (s3marks) is 585.

COUNT:

This function counts the number of rows (or non-NULL entries) in a column.

• Example: SELECT COUNT(sname) FROM student;


• This would give you the total number of students in the table by counting the no. of
students whose grade is “A” entries.

AVG:
This function calculates the average value of a column.

• Example: SELECT AVG(s1marks), AVG(s2marks), AVG(s3marks) FROM student;

• This would give you the average marks obtained in each subject (s1marks, s2marks,
and s3marks) across all students.

We computed the average marks for all students in each subject. This tells us the mean
score in each subject, giving us an idea of how students performed on average.

MAX:

This function finds the maximum value in a column.

• Example: SELECT MAX(s1marks), MAX(s2marks), MAX(s3marks) FROM student;


• This would give you the highest marks obtained in each subject (s1marks, s2marks,
s3marks).
• We found the highest marks achieved by any student in each subject. This helps
identify the top performer in each subject.

MIN:
This function finds the minimum value in a column.

• Example: SELECT MIN(s1marks), MIN(s2marks), MIN(s3marks) FROM student;

• This would give you the lowest marks obtained in each subject (s1marks, s2marks,
and s3marks).

• We identified the lowest marks obtained in each subject. This tells us the minimum
performance in each subject, indicating the lowest-scoring students.

RESULT:

Successfully implemented and tested numeric, string, date/time, and


aggregate functions in MySQL. Queries executed correctly, returning
expected results.

TASK-5
DATE:
AIM:: To understand and implement different types of joins in mysql.
JOINS:
Creation of the table;

Code::
create table employee(ename varchar(100), eid int primary key, esalary
varchar(10), profile varchar(12), did int);

• create table employee: Creates a new table named employee.


• Columns:
o ename: A string column for employee names (up to 100 characters).
o eid: An integer column for the employee ID (set as the primary key, ensuring
unique values).
o esalary: A string column for the employee salary (up to 10 characters).
o profile: A string column for the employee profile (up to 12 characters).
o did: An integer column, potentially referencing a department ID.

• Inserting the details;

Insert Data:

insert into employee(ename, eid, esalary, profile, did) values


('vijay', 1, 12, 'eng', 1),
('ajay', 2, 11, 'doc', 2),
('karthik', 3, 123, 'model', 1),
('koushik', 4, 124, 'writer', 3),
('santhi', 5, 112, 'pro', 2);

• insert into employee: Inserts rows into the employee table.


• Columns: Specifies values for ename, eid, esalary, profile, and did.
• Values: Five employee records are inserted with corresponding values for each
column (e.g., vijay, 1, 12, eng, 1).

Showing the table:

• SELECT * FROM employee; retrieves all rows and all columns from the employee table.
• The * is a wildcard that means "select all columns."

Creating another table:

Inserting the details into the table department;

Insert Data:
1. Basic Syntax for INSERT INTO:

INSERT INTO table_name (column1, column2, ...)


VALUES (value1, value2, ...),
(value1, value2, ...),
...;

• INSERT INTO department: This part specifies that you are inserting data into the
department table.
• (dname, did, dlocation): These are the column names in the department table where
data will be inserted.
• VALUES: This keyword introduces the values that you want to insert into the
specified columns.
• (value1, value2, value3): Each set of parentheses represents a new row to be inserted,
where the values correspond to the columns listed earlier.

2. Columns in the department Table:

• dname: Department name (e.g., 'it', 'cse', 'ece').


• did: Department ID (integer value, e.g., 1, 2).
• dlocation: The location of the department (e.g., 'buildingA', 'buildingB', 'buildingC').

❖ CROSS JOIN
➔ General Syntax for Selecting Data from Multiple Tables:

SELECT table1.column1, table1.column2, ...,table1.column_n,table2.column1,


table2.column2, ...,table2.column_n
FROM table1, table2;

This is a cross join (Cartesian product), which will return all combinations of rows from
table1 and table2. No filtering or matching conditions are applied.

❖ EQUI JOIN

General Syntax for Equi Join:

SELECT table1.column1, table1.column2, ..., table1.column_n, table2.column1,


table2.column2, ..., table2.column_n
FROM table1,
JOIN table2 ON table1.common_column = table2.common_column;

Key Points:

• table1.column1, table1.column2, ...: Specifies the columns from the first table you
want to retrieve.
• table2.column1, table2.column2, ...: Specifies the columns from the second table
you want to retrieve.
• FROM table1: The first table you're selecting data from.
• JOIN table2: Specifies the second table to join.
• ON table1.common_column = table2.common_column: The equivalence
condition for the join. The equality operator = is used to match rows from both tables
based on a shared column (the common_column), which typically has the same or
related values in both tables.
❖ LEFT OUTER JOIN :

General Syntax for Equi Join (LEFT OUTER JOIN):

SELECT table1.column1, table1.column2, ..., table1.column_n, table2.column1,


table2.column2, ..., table2.column_n
FROM table1
LEFT OUTER JOIN table2 ON table1.common_column = table2.common_column;

Key Points:

• table1.column1, table1.column2, ...: Specifies the columns you want to retrieve from
the first table (table1).
• table2.column1, table2.column2, ...: Specifies the columns you want to retrieve from
the second table (table2).
• FROM table1: The first table you're selecting data from.
• LEFT OUTER JOIN table2: Specifies the second table to join with the first table
using a LEFT OUTER JOIN.
o The LEFT OUTER JOIN will return all rows from table1 and the matched
rows from table2. If no match is found, NULL values are returned for columns
from table2.
• ON table1.common_column = table2.common_column: The equivalence
condition where the common_column from both tables is compared for equality
using the = operator. This defines how the rows will be matched between the two
tables.

❖ RIGHT OUTER JOIN :

SELECT table1.column1, table1.column2, ..., table1.column_n, table2.column1,


table2.column2, ..., table2.column_n
FROM table1
RIGHTOUTERJOIN table2 ON table1.common_column = table2.common_column;
Key Points:

• table1.column1, table1.column2, ...: Specifies the columns you want to retrieve from
the first table (table1).
• table2.column1, table2.column2, ...: Specifies the columns you want to retrieve from
the second table (table2).
• FROM table1: The first table you're selecting data from.
• RIGHT OUTER JOIN table2: Specifies the second table to join with the first table
using a RIGHT OUTER JOIN.
o The RIGHT OUTER JOIN will return all rows from table2 and the matched
rows from table1. If no match is found, NULL values are returned for columns
from table1.
• ON table1.common_column = table2.common_column: The equivalence condition
where the common_column from both tables is compared for equality using the =
operator. This defines how the rows will be matched between the two tables.

❖ FULL OUTER JOIN :

General Syntax for FULL OUTER JOIN in MySQL (Simulated with LEFT JOIN and
RIGHT JOIN):

SELECT table1.column1, table1.column2, ..., table1.column_n, table2.column1,


table2.column2, ..., table2.column_n
FROM table1
LEFTOUTERJOIN table2 ON table1.common_column = table2.common_column
UNION

SELECT table1.column1, table1.column2, ..., table1.column_n, table2.column1,


table2.column2, ..., table2.column_n
FROM table1
RIGHTOUTERJOIN table2 ON table1.common_column = table2.common_column;

Key Points:

• LEFT OUTER JOIN: This will return all rows from the first table (table1), and
matching rows from the second table (table2). If no match is found in table2, NULL
values will be returned for the columns from table2.
• RIGHT OUTER JOIN: This will return all rows from the second table (table2), and
matching rows from the first table (table1). If no match is found in table1, NULL
values will be returned for the columns from table1.
• UNION: Combines the result sets of both queries. It removes duplicate rows, thus
giving the effect of a FULL OUTER JOIN by combining rows from both tables that
have matching data as well as rows that don’t match from either table.

RESULT:: Sucesfully implemented the different type of joins.

Task-6

DATE:

AIM::To understand the different type of clauses in the dbms.

Clauses :
MySQL clauses are the foundational components used to construct database queries.
They define the structure and constraints of SQL statements, enabling efficient data
manipulation and retrieval. Clauses are integral to queries and work in conjunction
with other SQL components like keywords and functions.
Types of Clauses :
o Group by clause
o Having clause
o Order by clause
Create and Insert Values into table :
Group by Clause : The group by clause in SQL is used to arrange identical data
into groups based on one or more columns. This is often done in conjunction with
aggregate functions to perform operations on each group of data.

➢ Displaying maximum salary from Info table by grouping depid’s.

➢ Displaying average salary and depid from Info table by grouping depid’s.

➢ Displaying sum of salary from Info table by grouping depid.

Having Clause : The having clause in SQL is used to filter the results of a query
after the data has been grouped using the group by clause. It is similar to the where
clause, but while where is used to filter rows before grouping, having is used to filter
groups after the aggregation.

➢ Displaying maximum salary from Info table which is having depid =


‘101A’ by grouping depid.

Order by Clause : The order by clause in SQL is used to sort the result set of a
query in either ascending (ASC) or descending (DESC) order. This helps to organize
the data in a meaningful way, either by a single column or multiple columns.

➢ Displaying id from Info table in descending order of their salaries.

Result:: Successfully implemented and tested the different


clauses of dbms.
TASK-7
DATE::
AIM::
To understand and implement Nested Subqueries and Correlated Subqueries in
SQL by creating tables, inserting values, and performing queries to retrieve
specific data based on conditions.

SubQueries : Query in Query in called Subquery.


• Nested Subquery :
If the inner query execution is independent on outer query execution then it is called Nested
Subquery.

• Corelated Subquery :
If the inner query execution is dependent on outer query execution then it is called corelated
subquery.

➢ Create and insert values into table :


Nested Subquery :
➢ Displaying Name from Info table who is gaining high or maximum
salary.

➢ Displaying depid from det table of the one who is gaining high or
maximum salary from Info table.

➢ Displaying depname from det table where depid from Info table is having
maximum salary.
➢ Displaying depname from det table where depid from Info table is having
minimum salary.

Co-related Subquery :
➢ Displaying id , name and mobile from Info table where salary is greater
than average of ss

Key points::

➢ Depends on Outer Query: References outer query columns for evaluation.


➢ Row-by-Row Execution: Runs once for each outer query row.
➢ Used in WHERE: Often compares rows with related data.
➢ Performance Impact: Can be slow on large datasets.

Result:: Sucessfully implemented and tested the two different sub queries.
TASK-8
DATE::

AIM:: to understand and inmplement different type of set operations of mysql


Set Operations:
In order to use set operations we need have two or more tables with same data types.

Some of the set operations are union,union all,intersect and except.

Example tables are given below:

Union: It connects all the rows and removes the duplicate values.
Union all: it connects all the rows with the duplicates values.

Intersect: it prints the common values between two or more tables.

Except: it outputs the unique values from one table that are not in another table.

***********************Set Comparision operators:**************************

In MySQL, comparison operators are used to compare two values. They are commonly used
in SQL queries with WHERE, HAVING, or JOIN clauses to filter data based on certain
conditions. Here are the most common comparison operators:

IN operator: The IN operator allows you to specify multiple values in a WHERE clause.

The IN operator is a shorthand for multiple OR conditions.

The ANY operator:


• returns a boolean value as a result
• returns TRUE if ANY of the subquery values meet the condition

ANY means that the condition will be true if the operation is true for any of the values in the
range.

ALL operator: returns a boolean value as a result

returns TRUE if ALL of the subquery values meet the condition

is used with SELECT, WHERE and HAVING statements

EXISTS Operator: The EXISTS operator is used to test for the existence of any record in a
subquery.

The EXISTS operator returns TRUE if the subquery returns one or more records.

RESULT : Successfully implemented and tested the set operations of mysql


TASK 9
DATE:
AIM:: To understand and implement view on table.
Creation of a view:

➢ You can add SQL statements and functions to a view and present the data as if the
data were coming from one single table.
➢ A view is created with the CREATE VIEW statement.

Updation of a View:
➢ A view can be updated with the update statement.
Dropping a View:

➢ A view is deleted with the DROP VIEW statement.

Displaying of a view:

➢ The view can be displayed same as that of displaying normal table.

SUMMARY ON VIEWS::

Views in SQL:

1. Creation: A view is created using the CREATE VIEW statement, which combines
SQL statements and functions to present data as if from a single table.

2. Updation: A view can be updated using the UPDATE statement, allowing changes to
the underlying data.

3. Dropping: A view is deleted with the DROP VIEW statement.

4. Displaying: A view can be displayed like a normal table using a SELECT statement.

Result :: Sucessfully implemented the views on tables.

You might also like