A database is used to store the collection of records in an organized form.
It allows us to hold the
data into tables, rows, columns, and indexes to find the relevant information frequently. We can
access and manage the records through the database very easily.
Create database:
Query:
create database db_28_03_2023;
SHOW DATABASES;
Data Type:
The following table shows the summary of numeric types in MySQL:
Numeric Types Description
TINYINT A very small integer
SMALLINT A small integer
MEDIUMINT A medium-sized integer
INT A standard integer
BIGINT A large integer
DECIMAL A fixed-point number
FLOAT A single-precision floating point number
DOUBLE A double-precision floating point number
BIT A bit field
MySQL Boolean data type:
MySQL does not have the built-in BOOLEAN or BOOL data type. To represent boolean values, MySQL
uses the smallest integer type which is TINYINT(1). In other words, BOOLEAN and BOOL are
synonyms for TINYINT(1).
MySQL String data types:
String Types Description
CHAR A fixed-length nonbinary (character) string
VARCHAR A variable-length non-binary string
BINARY A fixed-length binary string
VARBINARY A variable-length binary string
TINYBLOB A very small BLOB (binary large object)
BLOB A small BLOB(binary large object)
MEDIUMBLOB A medium-sized BLOB
LONGBLOB A large BLOB
TINYTEXT A very small non-binary string
TEXT A small non-binary string
MEDIUMTEXT A medium-sized non-binary string
LONGTEXT A large non-binary string
ENUM An enumeration; each column value may be assigned one enumeration member
SET A set; each column value may be assigned zero or more SET members
MySQL date and time data types:
Date and Time Types Description
DATE A date value in CCYY-MM-DD format
TIME A time value in hh:mm:ss format
Date and Time Types Description
DATETIME A date and time value inCCYY-MM-DD hh:mm:ssformat
TIMESTAMP A timestamp value in CCYY-MM-DD hh:mm:ss format
YEAR A year value in CCYY or YY format
JSON data type:
MySQL supported a native JSON data type since version 5.7.8 that allows you to store and manage
JSON documents more effectively. The native JSON data type provides automatic validation of JSON
documents and optimal storage format.
Table Creation:
CREATE TABLE newtable (
id int NOT NULL,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(60) NULL,
email varchar(60) NOT NULL,
username varchar(120) not null,
password int not null,
PRIMARY KEY (id)
);
Insert query:
insert into newtable(id,firstname,lastname,email,username,password) values('1','1','1','1','1','1')
insert into newtable values(3,'1','1','1','1','1'),(4,'1','1','1','1','1')
ALTER TABLE old_table RENAME new_table;
ALTER TABLE table_name ADD column_name datatype;
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name RENAME COLUMN old_name to new_name;
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
ALTER TABLE newtable MODIFY firstname varchar(200) AFTER password;
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
Data
Type “Zero” Value
DATE '0000-00-00'
TIME '00:00:00'
DATETIME '0000-00-00 00:00:00'
TIMESTAMP '0000-00-00 00:00:00'
YEAR 0000