Dbms File (22001003002) (AutoRecovered)
Dbms File (22001003002) (AutoRecovered)
OF
Database Management Systems
(CSE383C)
What is MySQL ?
MySQL is one of the most popular relational database management software thatis widely
used in today's industry. It provides multi-user access support with various storage
engines. It is backed by Oracle Company.
Step 2: Next, there are two options available to download the setup. Choose the version
number for the MySQL community server, which you want. If you have good internet
connectivity, then choose the mysql-installer-web-community. Otherwise, choose the other
one.
Aaditya 22001003002
Step 2: In the next wizard, choose the Setup Type. There are several types available, and you
need to choose the appropriate option to install MySQL product and features. Here, we are
going to select the Full option and click on the Next button.
This option will install the following things: MySQL Server, MySQL Shell, MySQL Router,
MySQL Workbench, MySQL Connectors, documentation, samples andexamples, and many
more.
Step 3: Once we click on the Next button, it may give information about some features that
may fail to install on your system due to a lack of requirements. We can resolve them by
clicking on the Execute button that will install all requirements automatically or can skip
them. Now, click on the Next button.
Step 4: In the next wizard, we will see a dialog box that asks for our confirmation of afew
products not getting installed. Here, we have to click on the Yes button.
Aaditya 22001003002
After clicking on the Yes button, we will see the list of the products which are going to be
installed. So, if we need all products, click on the Execute button.
Step 5: Once we click on the Execute button, it will download and install all the products.
After completing the installation, click on the Next button.
Step 6: In the next wizard, we need to configure the MySQL Server and Router. Here , I am
not going to configure the Router because there is no need to use it with MySQL. We are
going to show you how to configure the server only. Now, click on the Next button.
Aaditya 22001003002
Step 7: As soon as you will click on the Next button, you can see the screen below. Here, we
have to configure the MySQL Server. Now, choose the Standalone MySQL Server/Classic
MySQL Replication option and click on Next. Here, you can also choose the In no DB
Cluster based on your needs.
Step 8: In the next screen, the system will ask you to choose the Config Type and other
connectivity options. Here, we are going to select the Config Type as 'Development
Machine' and Connectivity as TCP/IP, and Port Number is 3306, then click on Next.
Step 9: Now, select the Authentication Method and click on Next. Here, I am going toselect
the first option.
Aaditya 22001003002
Step 10: The next screen will ask you to mention the MySQL Root Password. Afterfilling
the password details, click on the Next button.
Step 11: The next screen will ask you to configure the Windows Service to start theserver.
Keep the default setup and click on the Next button.
Step 12: In the next wizard, the system will ask you to apply the Server Configuration.If you
agree with this configuration, click on the Execute button.
Aaditya 22001003002
Step 13: Once the configuration has completed, you will get the screen below. Now, click on
the Finish button to continue.
Step 14: In the next screen, you can see that the Product Configuration is completed.Keep the
default setting and click on the Next-> Finish button to complete the MySQL package
installation.
Step 15: In the next wizard, we can choose to configure the Router. So click on Next-
>Finish and then click the Next button.
Aaditya 22001003002
Step 16: In the next wizard, we will see the Connect to Server option. Here, we have to
mention the root password, which we had set in the previous steps.
In this screen, it is also required to check about the connection is successful or not byclicking
on the Check button. If the connection is successful, click on the Execute button. Now, the
configuration is complete, click on Next.
Step 17: In the next wizard, select the applied configurations and click on the Executebutton.
Step 18: After completing the above step, we will get the following screen. Here, clickon the
Finish button.
Aaditya 22001003002
Step 19: Now, the MySQL installation is complete. Click on the Finish button.
Open your MySQL Command Line Client; it should have appeared with a mysql> prompt.
If you have set any password, write your password here. Now, you are connected to the
MySQL server, and you can execute all the SQL command at mysql>prompt as follows:
For example: Check the already created databases with show databases command:
Aaditya 22001003002
Experiment - 2
Aim: Study of Various Data Types of and Data Objects in SQL.
In SQL (Structured Query Language), data types are essential components that define
the type of data stored in a column or variable within a database table. Here's a
detailed explanation of various data types commonly used in SQL:
Data Types:
1. Numeric Types:
INT, INTEGER: Represents whole numbers within a specified range.
SMALLINT: Similar to INT but with a smaller range.
BIGINT: Allows storage of large integer values.
DECIMAL(p, s), NUMERIC(p, s): Fixed-point numbers with
user- specified precision and scale.
FLOAT(p): Floating-point numbers with user-specified precision.
REAL: Single precision floating-point number.
DOUBLE PRECISION: Double precision floating-point number.
2. Character String Types:
CHAR(n): Fixed-length character string with a specified length.
VARCHAR(n): Variable-length character string with a
maximum length.
TEXT: Variable-length character string with no specified
maximum length.
NCHAR(n), NVARCHAR(n), NTEXT: Same as above but
for Unicode characters (national character set).
3. Binary Data Types:
BINARY(n): Fixed-length binary string with a specified length.
VARBINARY(n): Variable-length binary string with a
maximum length.
BLOB: Binary Large Object for storing large binary data.
BIT: Stores bit values or binary data.
Aaditya 22001003002
4. Date and Time Types:
DATE: Stores date values without a time component.
TIME: Stores time values without a date component.
DATETIME: Stores date and time values together.
TIMESTAMP: Represents a point in time, typically used for
recording when data was last modified.
INTERVAL: Represents a time span or duration.
5. Boolean Type:
BOOLEAN, BOOL: Represents boolean values, typically TRUE or
FALSE.
6. Other Data Types:
XML: Stores XML data.
JSON: Stores JSON data.
GEOMETRY: Stores geometric data.
GEOGRAPHY: Stores geographic data.
ARRAY: Stores an array of elements.
These descriptions provide an overview of each data type's purpose and usage in SQL
databases. Keep in mind that some data types might not be supported in all SQL
database management systems, and there could be variations in naming and
implementation across different systems.
Data Objects:
In SQL, object types refer to the various constructs used to define and manage
database objects. Here are some common object types in SQL:
1. Tables:
Tables are the most fundamental database objects used to store
and organize data in rows and columns.
2. Indexes:
Indexes are used to improve the performance of database queries
by providing faster access to data based on specific columns.
3. Views:
Aaditya 22001003002
Views are virtual tables that are defined by a query and do not store
data themselves. They provide a way to simplify complex queries and
present data in a structured format.
4. Constraints:
Constraints are rules enforced on data columns to maintain data
integrity. Examples include primary key, foreign key, unique,
check, and not null constraints.
5. Stored Procedures:
Stored procedures are precompiled SQL statements or routines stored in
the database server. They can accept parameters, execute SQL
statements, and return results.
6. Functions:
Functions are similar to stored procedures but return a single value.
They can be user-defined or built-in functions provided by the
database system.
7. Triggers:
Triggers are special types of stored procedures that are automatically
executed or fired in response to specific events, such as insert, update,
or delete operations on tables.
8. Sequences:
Sequences are database objects used to generate unique numeric
values, typically used for primary keys.
9. Synonyms:
Synonyms are aliases for database objects such as tables, views, or
stored procedures, providing an alternative name for easier reference.
10. Roles:
Roles are named groups of privileges that can be assigned to users or
other roles, simplifying the management of permissions in a
database.
11. Users:
Users are accounts that can access and interact with a database. They
are granted specific permissions to perform operations on database
objects.
12. Database:
Database is the top-level container that holds all database
objects, including tables, views, indexes, and stored procedures.
Aaditya 22001003002
13. Schema:
Schema is a logical container within a database that contains database
objects such as tables, views, and stored procedures. It provides a way
to organize and manage objects.
14. Extensions:
Extensions are add-on modules that provide additional functionality to
a database system, such as new data types, functions, or procedural
languages.
15. Foreign Data Wrappers (FDW):
FDWs are extensions that allow a database to access and interact
with external data sources, such as other databases or web services.
16. Foreign Servers:
Foreign servers are configurations that define connections to
external data sources, enabling the database to communicate with
remote databases or servers.
17. Event Scheduler:
Event scheduler is a component that allows scheduling and execution
of recurring tasks or events within the database server.
18. User-Defined Types:
User-defined types allow users to define custom data types based
on their specific requirements, providing flexibility in data
modeling.
19. User-Defined Aggregates:
User-defined aggregates allow users to define custom
aggregate functions for performing calculations on groups of
data.
20. User-Defined Operators:
User-defined operators allow users to define custom operators for
performing operations on data types that are not supported by default
in the database system.
These object types are fundamental components of SQL databases and are used to
define, manage, and manipulate data and database structures. Depending on the
specific database management system (DBMS), additional object types or variations
may exist.
Aaditya 22001003002
Experiment - 3
Aim: Implementation of DDL Commands in SQL.
1. Create command:
a) Creating database:
Code :
Create database university;
Output:
b) Creating table:
Code :
Create table student(Student_id int not null, S_name varchar(10),Dept char(3));
Output:
2. Alter command:
a) to add column:
Code :
Alter table student add email varchar(100);
Aaditya 22001003002
Output:
b) to modify column:
Code :
Alter table student modify dept varchar(10) ;
Output:
c) to drop column:
Code :
Alter table student drop column email;
Output:
Aaditya 22001003002
3. Rename command:
Code :
Alter table student rename column student_id to s_id;
Output:
4. Truncate command:
Code :
Truncate table student;
Output:
5. Drop command:
Code :
Drop table student;
Output:
Aaditya 22001003002
Experiment - 4
AIM: Implementation of DML Commands in SQL.
1. Insert command:
Code :
Output:
2. Update command:
Code :
Output:
Aaditya 22001003002
3. Select command:
Code :
Output:
Code :
Output:
4. Delete command:
Code :
Output:
Aaditya 22001003002
Experiment - 5
AIM: Implementation of various aggregate functions in SQL with
group by and Having Clause.
SQL Aggregate functions are functions where the values of multiple rows are
grouped as input on certain criteria to form a single value result of more
significant meaning.
1. COUNT()
The COUNT() function returns the number of rows that matches a specified
criterion.
2. SUM()
3. AVG()
4. MIN()
5. MAX()
Aaditya 22001003002
1. COUNT()
a) to count all records by marks
Code :
Output:
Code :
Output:
Code :
Aaditya 22001003002
Output :
2. SUM()
a) sum of all records marks
Code :
select sum(marks) from student;
Output :
Code :
select sum(DISTINCT marks) from student;
Output :
Aaditya 22001003002
c) using group by and having clause
Code :
select s_name from student group by s_name having sum(marks)>95;
Output :
3. AVG()
a) average of all records marks
Code :
select avg(marks) from student;
Output :
Code :
select s_name from student group by s_name having avg(marks)>93;
Aaditya 22001003002
Output :
4. MAX()
a) maximum value from marks
Code :
select max(marks) from student;
Output :
Code :
select s_name from student group by s_name having max(marks)>94;
Output :
Aaditya 22001003002
5. MIN()
a) minimum value from marks
Code :
select min(marks) from student;
Output :
Code :
select s_name from student group by s_name having min(marks)<94;
Output :
Aaditya 22001003002
Experiment - 6
AIM: Implementation of various String functions in SQL.
String functions
String functions are used to perform an operation on input string and return an
output string.
Code :
select char_length('Deepak');
Output :
Code :
Output :
Aaditya 22001003002
2. a) CONCAT(): This function is used to add two words or strings.
Code :
select concat('coding','ninjas');
Output :
Code :
select concat_ws('_','coding','ninjas');
Output :
Code :
select format("0.67","percent");
Output :
Aaditya 22001003002
4. a) LCASE(): This function is used to convert the given string into lower case.
Code :
Output :
Code :
Output :
5. a) LTRIM(): This function is used to cut the given sub string from the original
string.
Code :
Output :
Aaditya 22001003002
b) RTRIM(): This function is used to cut the given sub string from the original
string.
Code :
Output :
6. MID(): This function is to find a word from the given position and of the
given size.
Code :
select mid("geeksforgeeks",9,5);
Output :
Code :
select position("o"in"geeksforgeeks");
Output :
Aaditya 22001003002
8. REVERSE(): This function is used to reverse a string.
Code :
select reverse("geeksforgeeks");
Output :
9. REPEAT(): This function is used to write the given string again and again till
the number of times mentioned.
Code :
select repeat('geeks','2');
Output :
10. LOCATE(): This function is used to find the nth position of the given word
in a string.
Code :
select locate('geeks','geeksforgeeks','2');
Output :
Aaditya 22001003002
Experiment - 7
AIM: Implementation of various DateFunctions in SQL.
Date Functions
In SQL, dates are complicated for newbies, since while working with a database,
the format of the date in the table must be matched with the input date in order to
insert. In various scenarios instead of date, datetime (time is also involved with
date) is used.
Code :
SELECT CURDATE();
Output :
Code :
SELECT CURTIME();
Output :
Aaditya 22001003002
2. a) DATEDIFF(): It returns the difference in days between two date values.
Code :
Output :
Code :
Output :
Code :
Output :
Aaditya 22001003002
b) DATE_SUB(): It returns a date after a certain time/date interval has been
subtracted.
Code :
Output :
Code :
Output :
Code :
SELECT SECOND("09:14:23:00032");
Output :
Aaditya 22001003002
c) MINUTE(): It returns the minute portion of a date value.
Code :
Output :
Code :
Output :
Code :
SELECT DAY(“2018-07-16”);
Output :
Aaditya 22001003002
f) WEEK(): It returns the week portion of a date value.
Code :
SELECT WEEK("2018-07-18");
Output :
Code :
Output :
Code :
SELECT YEAR("2018-07-18");
Output :
Aaditya 22001003002
5. a) DAYNAME(): It returns the weekday name for a date.
Code :
SELECT DAYNAME('2008-05-15');
Output :
Code :
SELECT MONTHNAME("2018/07/18");
Output :
Code :
SELECT DAYOFMONTH('2018-07-16');
Output :
Aaditya 22001003002
b) DAYOFYEAR(): It returns the day of the year for a date value.
Code :
SELECT DAYOFYEAR("2018-07-16");
Output :
Code :
SELECT WEEKOFYEAR("2018-07-18");
Output :
Code :
Output :
Aaditya 22001003002
8. LAST_DAY(): It returns the last day of the month for a given date.
Code :
SELECT LAST_DAY('2018-07-16');
Output :
Code :
SELECT TIME_TO_SEC("09:16:10");
Output :
10. a) MAKEDATE(): It returns the date for a certain year and day-of-year value.
Code :
Output :
Aaditya 22001003002
b) MAKETIME(): It returns the time for a certain hour, minute, second
combination.
Code :
SELECT MAKETIME(11, 35, 4);
Output :
Aaditya 22001003002
Experiment - 8
AIM: Implementation of Data Control Language (DCL) Commands
in SQL.
DCL includes commands such as GRANT and REVOKE which mainly deal with
the rights, permissions, and other controls of the database system.
1. GRANT
2. REVOKE
Code :
Output :
Aaditya 22001003002
1. GRANT: This command gives users access privileges to the database.
Code :
Output :
Code :
Output :
Aaditya 22001003002
Experiment - 9
AIM: Implantation of Data Integrity Constraintsin SQL.
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures
the accuracy and reliability of the data in the table. If there is any violation between
the constraint and the data action, the action is aborted.
Code :
Output :
Aaditya 22001003002
UNIQUE - Ensures that all values in a column are different
Code :
Output :
Code :
Output :
Aaditya 22001003002
CHECK - Ensures that the values in a column satisfies a specific condition
Code :
Output :
Code :
Output :
Aaditya 22001003002