SQL Data Types
SQL Data Types
SQL Data Types
Data types are used to represent the nature of the data that can be stored in the
database table. For example, in a particular column of a table, if we want to store
a string type of data then we will have to declare a string data type of this
column.
Data types are mainly classified into three categories for every database:
BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size
parameter specifies the column length in the bytes. Default is
1.
ENUM(val1, val2, val3,...) It is used when a string object has only one value, chosen from a
list of possible values. It contains 65535 values in an ENUM list.
If you insert a value that is not in the list, a blank value will be
inserted.
SET( val1,val2,val3,....) It is used to specify a string that can have 0 or more values,
chosen from a list of possible values. You can list up to 64
values at one time in a SET list.
BIT(Size) It is used for a bit-value type. The number of bits per value
is specified in size. Its size can be 1 to 64. The default
value is 1.
INT(size) It is used for the integer value. Its signed range varies from
-2147483648 to 2147483647 and unsigned range varies
from 0 to 4294967295. The size parameter specifies the
max display width that is 255.
Database engines are MySQL components that can handle SQL operations
like create, read, update data from a database. There are two types of engines
in MySQL: transactional and non-transactional.InnoDB is the default engine
for MySQL 5.5 and above versions. Major DBMS uses an application
programming interface(API) to enable the interaction of users with database
engines. It is very necessary to know about the engines for production
databases and it also impacts future development. To access the list of
available MySQL engines we run SHOW ENGINES; query.
Transactional Databases: In this type, we can roll back the write operations on
the database if they are left incomplete. These operations are known as
transactions. Majorly, modern engines are transactional.
rollback operations.
TCL (Transaction Control
Language):
Transactions group a set of tasks into a single execution unit. Each transaction begins with a
specific task and ends when all the tasks in the group successfully complete. If any of the tasks
fail, the transaction fails. Therefore, a transaction has only two results: success or failure. You
can explore more about transactions here.
Hence, the following TCL commands are used to control the execution of a transaction:
● ROLLBACK: It is used to restore the database to that state which was last committed.
● SAVEPOINT: The changes done till savepoint will be unchanged and all the transactions
after savepoint will be rolled back.
DDL or Data Definition Language actually consists of the SQL commands that can be used to
define the database schema. It simply deals with descriptions of the database schema and is
used to create and modify the structure of database objects in the database. DDL is a set of
SQL commands used to create, modify, and delete database structures but not data. These
commands are normally not used by a general user, who should be accessing the database via
an application.
List of DDL commands:
● CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
● TRUNCATE: This is used to remove all records from a table, including all spaces
allocated for the records are removed.
DML(Data Manipulation
Language):
The SQL commands that deal with the manipulation of data present in the database belong to
DML or Data Manipulation Language 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.