DEV Community

Cover image for SQL Datatypes and Commands
EzeanaMichael
EzeanaMichael

Posted on

SQL Datatypes and Commands

Datatypes define how characters, letters, or numbers are stored in a database to perform some operations and for easier access, use, and understanding by the computer.

Datatypes in SQL

Some of the main datatypes used in SQL include:

  • CHAR: The CHAR data type can store from 1 to 255 characters, it is used when inputting string characters in the database table. It stores a fixed length of characters. For example, CHAR(30) can store only up to 30 characters in a field.
  • VARCHAR: The VARCHAR datatype can store a variable length of characters. Unlike the CHAR datatype which uses the fixed length which takes more space in memory due to the fixed length, the VARCHAR can use the minimum number of lengths and space depending on the length of characters needed.
  • ENUM: This is a datatype that can store numbers and characters together.
  • BOOLEAN: This datatype stores values in terms of True and False.
  • INT: This datatype is used to store integer values.
  • FLOAT: This datatype stores floating-point numbers or approximate numeric values i.e decimal numbers.
  • DOUBLE: This datatype stores double precision floating point values up to a precision of 64.
  • DATE: This datatype accepts only date values in the form yyyy-mm-dd(year-month-date).
  • TIME: This datatype accepts time values in the form hh-mm-ss(hours-minutes-seconds).

Other Datatypes include binary, varbinary, year, tinyblob, blob, medium blob, long blob, set, bit, timestamp, tiny text, text, medium text and long text, tiny int, small int, medium int, big int, datetime, decimal. The three main ways data are stored in SQL are character, numeric, and date.

Commands in SQL:

There are 4 main types of commands Groups in SQL, these are:

  • DDL(Data Definition Language): These are the Commands which define the database structure. They create database objects and can affect or create views and tables. Examples of these include: CREATE TABLE, ALTER TABLE, DROP TABLE, and so on.

  • DML(Data Manipulation Language): These are commands that are used to modify databases and manipulate or control tables when to produce the desired result. Examples include: INSERT, UPDATE, and DELETE.

  • DCL(Data Control Language): These are the commands used for controlling and issuing security constraints on the database. Examples include GRANT, and REVOKE.

  • DQL(Data Query Language): These are commands used to fetch useful information from the database without affecting the data present in it. Examples include SELECT.

Top comments (0)