Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

MySQL Features

MySQL is most popular Open Source Database software and


available at free of cost. Features of MySQL are:

 Portability:- MySQL can be installed and run on any types of


Hardware and OS like Linux, MS Windows or Mac etc.
 Security:- Its Databases are secured & protected with
password.
 Connectivity:- It supports the data base connectivitywith many
programming languages.
 Query Language:- It supports SQL (Structured Query
Language) for handling database.
Classification of SQL Commands/Statements

SQL commands are classified in four categories:

SQL Statement

DDL DML DCL TCL


(Transaction
(Data Definition (Data Manipulation (Data Control
Control
Language) Language) Language)
Language)
SQL COMMANDS

 DDL Commands:- These commands are used to perform task


on the structure of table and database.
Examples: Create, Alter, Drop
 DML Commands:- These commands are used to manipulate
the data of the table.
Examples: Select, Insert, Update, Delete
 DCL Commands:- These commands are used to control the
accessibility of the database/tables.
Examples: Grant, Revoke
 TCL Commands:- These commands are used to manage and
control the transactions. i.e. these are used to manage the
changes made by DML commands.
Examples: Commit, Rollback, SavePoint
DATA TYPES IN SQL
 Numeric Data Types:-
int
integer Perfect Integer value
int(size)
decimal(x,y)
float(x,y) Decimal value
double(x,y)

String or Text Types:-


char(size) # Fixed length character
varchar(size) # Variable length character

Date and Time Types:-


date # Format- ‘YYY-MM-DD’
time # Format- ‘HH:MM:SS’
datetime # Format- ‘YYY-MM-DD HH:MM:SS’
CONSTRAINTS IN SQL
The following constraints are commonly used in SQL:
NOT NULL- It Ensures that a column cannot have a NULL(Blank) value.
 UNIQUE- It Ensures that all values in a column are different/unique.
 PRIMARY KEY - A combination of a NOT NULL and Unique. i.e. column
with Primary key neither can have duplicate value nor left blank. It uniquely
identifies each row in a table.
 CHECK - It Ensures that all values in a column satisfies a specified
condition or range of value.
 DEFAULT - It sets a default value for a column when no value is specified
or entered by user.
 FOREIGN KEY - It connects two tables or uniquely identified records in
another table.
SQL COMMANDS FOR DATABASE
Suppose I want to create a database with ‘DPS’. We can perform the
following SQL commands on database.
 Create Command - This command is used to create the database.
Syntax: Create database <database name>;
e.g. create database DPS;
 Drop Command - This command is used to remove the database.
Syntax: Drop database <database name>;
e.g. drop database DPS;
 Use Command - This command is open the specified database to
work on it.
Syntax: Use <database name>;
e.g. use DPS;
 Show Command - This command is used to display the list of all the
databases and tables.
e.g. show databases;
SQL COMMANDS
FOR
TABLE
CREATE TABLE STATEMENT
Create command is used to create the table. While creating
the table we have to specify the definition of each and
every column of the table like column name, its data type
and constraint(optional).

Syntax:
create table <table name>
( <column1> <datatype> [<constraint>],
<column2> <datatype> [<constraint>],
<column3> <datatype> [<constraint>],
-----------
);
CREATE TABLE ‘STUDENT’
Rollno Name Age Gender DOB Class Fee
1 Ankit Kumar 14 M 2006-02-10 10 700
2 Payal Sharma 13 F NULLL 9 900
3 Mohit 17 M 2003-05-12 11 1000
4 Priyanka Singh 18 F 2001-12-23 12 1500
5 Anjali Kapoor 15 F 2004-08-28 10 800
6 Sanket 18 M NULL 12 700
7 Rahul Kumar 15 M 2004-10-22 10 1200
Singh

mysql>Create table Student


(Rollno integer Primary key,
Name varchar(30),
Age int(2) not null,
Gender char(1),
DOB date,
Class int(2),
Fee integer);
INSER COMMAND
 To insert the value for all the columns of table
insert into student values(1, ’Ankit Kumar’, 24, ‘M’, ‘1996-02-10’, 700);

 To insert the value of specific columns


insert into student(Rollno, Name,Age,Gender,Fee) values(2, ’Payal Sharma’,
23, ‘F’, 900);
OR

insert into student values(2, ’Payal Sharma’, 23, ‘F’, NULL,900);

You might also like