Arrow

Introduction to SQL

AuthorHariom Prajapati

Pubish Date03 Jul 2022

categoryMySql

What is SQL?

Full form of SQL is Structured Query Language, that could be a language to storing, retrieving and manipulating information stored in a relational database.

SQL is a standard language for Relational Database System (RDS).

All the Relational Database Management Systems (RDMS) like MySQL, Oracle, Sybase, Postgres , SQL Server etc. use SQL language.

 

Why SQL?

SQL is most popular because SQL offers the following advantages −

  • Using SQL user can access data in the relational database management systems.

  • Using SQL user can describe the data.

  • Using SQL user can define the data in a database and manipulate that data.

  • Using SQL user can create and drop databases and tables.

  • Using SQL user can create view, stored procedure, functions in a database.

  • Using SQL user can set permissions on tables, procedures and views.

 

Database

The database is a collection of data (or information).

 

Relation database

A relational database is tables, where tables are related to one another in the database. This type of database allows data to be broken down into smaller, manageable, and logical units for better performance and maintenance.

 

Database management system

The software used to manage the database is called Database Management System (DBMS). For Example, Oracle, MySQL are the most popular commercial DBMS which used in different applications.

 

Standard query language (SQL)

SQL stands for Structured Query Language. SQL is a standard programming language which designed for storing, retrieving, managing or manipulating the data in a relational database management system.

we can do many more thing with SQL:

  • 1) We can create a database.
  • 2) We can create tables in the database.
  • 3) we can query or request information from the database.
  • 4) we can insert records into the database.
  • 5) we can modify or update records in the database.
  • 6) we can delete any records from the database.

 

Data type

Data types use to enter value in the table.

Data type is divided into these categories:-

NUMERIC TYPE STRING TYPE DATE TYPE
Smallint Varchar Datetime
Int Char Date
Double Text --
Float Longblob --
Numeric Mediumblob --
Decimal Tinyblob --
Bigint blob year
binary bit year

 

MySQL String Data Types

CHAR(Size) It is used to specify a fixed-length string that contains numbers, letters, and special characters. Its size can be 0 to 255 characters.
VARCHAR(Size) It is used to specify a variable-length string that can contain numbers, letters, and special characters. Its size can be from 0 to 65535 characters.
BINARY(Size) It is same to CHAR() but stores binary byte strings.
VARBINARY(Size) It is same as VARCHAR() but stores binary byte strings.
TEXT(Size) It can hold a string that contains a maximum length of 255 characters.
TINYTEXT It can holds string with a maximum length of 255 characters.
MEDIUMTEXT It can holds string with a maximum length of 16,777,215.
SET( val1,val2,val3,....) SET is used to specify a string that can have 0 or more values.
BLOB(size) It is used for Binary Large Objects. It can hold up to 65,535 bytes.

 

MySQL Numeric Data Types

INT(size) It is used for the integer value.
FLOAT It is used to specify a floating-point number which has a decimal value.
BOOL It is specified Boolean values true and false. Zero is false, and nonzero values are true.

 

MySQL Date and Time Data Types

DATE It is used to specify a date in the format YYYY-MM-DD.
DATETIME(fsp) It is used to specify the date and time. the format is YYYY-MM-DD hh:mm:ss.
TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss.
YEAR It s used to specify the year in four-digit format. Values allowed in four-digit from 1901 to 2155, and 0000.