You are on page 1of 15

Managing MySQL databases and

tables in MySQL
What is DataBase???
• What name suggest…
– Data + Base= Database
– Data means raw information
– Base means holding place/storage area
– Database is a store house of raw information.
So why database to study?

Database allows manage


your information in a
organized and secure way.
Show Databases and Tables

1. For showing existing databases:


Show databases;
2. For showing existing tables in a database:
Show tables;
• Create database
Syntax: create database database_name;
Example : create database fall_2020;
Use database
Syntax: use database_name;
Example: use fall_2020
• Create a table
Syntax:
create table student
( ID int,
Firstname varchar(255),
Lastname varchar(255),
Address varchar(255),
City varchar(255)
);
• Describe table student :
describe student;
• Insert value into student table:
insert
 into student(ID, Firstname, Lastname, Address, Ci
ty) values
(17100201,'sakib','hasan','dhaka',’sylhet’);
insert into
student(id,Firstname,Lastname,Address,City)
values(17100202,'sakib','zaman','dhaka','sylhet');
• Insert value into student table(another way):
insert into
student(ID,Firstname,Lastname,Address,City)
VALUES(12,'ss','dd','dhaka','sylhet'),
(13,'dd','ss','dhk','sl'),
(13,'dd','ss','dhk','sl');
• Find the all value from table student:
Select * from student;
• MySQL supports a number of SQL standard
data types in various categories. MySQL
has Numeric Types, the Date and Time
Types(DATETIME, DATE,
and TIMESTAMP) Types and String Types.
Float datatype syntax: FLOAT(M,D)
create table test(
id int,
name varchar(20),
mark float(3,2)
);
• insert into test(id,name,mark)
values(101,'dd',3.05);
Date and Time Types
Types Description Display Format Range
DATETIME Use when you need YYYY-MM-DD '1000-01-01 00:00:00'
values containing HH:MM:SS to '9999-12-31
both date and time 23:59:59'.
information.

DATE Use when you need YYYY-MM-DD '1000-01-01' to '9999-


only date information. 12-31'.
TIMESTAMP Values are converted YYYY-MM-DD '1970-01-01 00:00:01'
from the current time HH:MM:SS UTC to '2038-01-19
zone to UTC while 03:14:07' UTC
storing and converted
back from UTC to the
current time zone
when retrieved.
Create table testdate(
id int,
name varchar(20),
Birthdate date,
Orderdate datetime,
Entrydate datetime default current_timestamp
);
• insert into
testdate(id,name,Birthdate,Orderdate)
values(1,'sakib','1994-12-12','2010-12-12
12:12:12');

You might also like