Installing MySQL
This is the site to install MySQL- https://www.mysql.com/downloads/
Database Management System(DBMS)
Most used DBMS
• MySQL
• Oracle
• Microsoft SQL
• PostgreSQL
• MongoDB
Advantages of DBMS
RDBMS
• The data in RDBMS is stored in database objects called tables. A table is a collection of related
data entries, and it consists of columns and rows.
• A record, also called a row, is each individual entry that exists in a table.
• A column is a vertical entity in a table that contains all information associated with a specific field
in a table.
What is SQL?
•SQL stands for Structured Query Language
•SQL lets you access and manipulate databases
•SQL became a standard of the American National Standards
Institute (ANSI) in 1986, and of the International
Organization for Standardization (ISO) in 1987
What Can SQL do?
SQL is very powerful
•SQL can execute queries against a database
•SQL can retrieve data from a database
•SQL can insert records in a database
•SQL can update records in a database
•SQL can delete records from a database
•SQL can create new databases
•SQL can create new tables in a database
•SQL can create stored procedures in a database
•SQL can create views in a database
•SQL can set permissions on tables, procedures, and views
MySQL Data Type
The data type of a column defines what value the column can hold: integer,
character, money, date and time, binary, and so on.
In MySQL there are three main data types: string, numeric, and date and time.
String Data types in MySQL
MySQL Data Type
Date Data types in MySQL
MySQL Data Type
Numeric Data types in MySQL
Types of Commands in SQL
DDL DML DQL DCL
Create Insert Select Grant
Alter Update Revoke
Drop Delete
Truncate
Rename
DDL- Data Definition Language
It consists of SQL commands that can be used to define the
database structures but not data.
CREATE: This command is used to create the database or its
objects (like table, index, function, views, store procedure,
and triggers).
DROP: This command is used to delete objects from the
database.
ALTER: This is used to alter the structure of the database.
TRUNCATE: This is used to remove all records from a table,
including all spaces allocated for the records are removed.
RENAME: This is used to rename an object existing in the
database.
SQL CREATE ,DROP, TRUNCATE
CREATE DATABASE
DROP DATABASE
CREATE TABLE
DROP TABLE
TRUNCATE TABLE
SQL ALTER TABLE
ALTER TABLE - ADD Column
ALTER TABLE - DROP COLUMN
ALTER TABLE - RENAME Column
ALTER TABLE - ALTER/MODIFY DATATYPE
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.
Constraints can be column level or table level.
The following constraints are commonly used in SQL:
•NOT NULL - Ensures that a column cannot have a NULL value
•UNIQUE - Ensures that all values in a column are different
•PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely
identifies each row in a table
•FOREIGN KEY - Prevents actions that would destroy links between tables
•CHECK - Ensures that the values in a column satisfies a specific condition
•DEFAULT - Sets a default value for a column if no value is specified
DML(Data Manipulation Language)
The SQL commands that deal with the manipulation of data
present in the database belong to DML and this includes
most of the SQL statements. It is the component of the SQL
statement that controls access to data and to the database.
Basically, DCL statements are grouped with DML
statements.
• INSERT: It is used to insert data into a table.
• UPDATE: It is used to update existing data within a
table.
• DELETE: It is used to delete records from a database
table.
DQL(Data Query Language)
• It is a SQL statement that allows getting data from the
database and imposing order upon it.
• It includes the SELECT statement.
• This command allows getting the data out of the
database to perform operations with it.
• When a SELECT is fired against a table or tables the
result is compiled into a further temporary table, which
is displayed or perhaps received by the program i.e. a
front-end.
DCL(Data Control Language)
• It includes commands such as GRANT and REVOKE
which mainly deal with the rights, permissions, and
other controls of the database system.
• GRANT: This command gives users access privileges to
the database.
• REVOKE: This command withdraws the user’s access
privileges given by using the GRANT command.
Things to remember!!
•SQL keywords are NOT case sensitive:
select is the same as SELECT
• Some database systems require a semicolon at the end of each SQL
statement.
• Semicolon is the standard way to separate each SQL statement in
database systems that allow more than one SQL statement to be
executed in the same call to the server.
• In this tutorial, we will use semicolon at the end of each SQL
statement.