STRUCTURED QUERY LANGUAGE (SQL)

SQL is one of the most important tool a Data Scientist or a Data analyst should know of. SQL is a query language which is used to manipulate and retrieve information from a Database.

SQL is used with R-DBMS (Relationship Database Management System) for retrieving and querying purpose.

In this blog, we will look into various basic SQL queries , where and when those queries are used.

There are five types of SQL commands:

  • DDL — Data Definition Language
  • **DQL **— Data Query Language
  • **DML **— Data Manipulation Language
  • **DCL **— Data Control Language
  • **TCL **— Transaction Control Language

DDL — Data Manipulation Language:

The DDL commands are used to define the structure of the database. It is used for creating and modifying the database objects such as table, indexes etc… The basic DDL Commands are:

  • **CREATE **-it is used for creation of a database or table.

CREATE TABLE <table_name> (

<column_name1> datatype,

<column_name2> datatype,

<column_name3> datatype,

….

);

  • **DROP **-it is used to delete objects from the database.

DROP TABLE <table_name>;

  • **TRUNCATE **- it is used to remove the contents/records in a table but not the table itself (i.e) the structure of the table remains as it is.

TRUNCATE TABLE <table_name>;

  • **ALTER **- Alter command is used to alter the existing structure of the table. It is used to add, delete, or modify columns in an existing table as well as it can be used to add constraints to a table.

ALTER TABLE <table_name>

ADD <column_name> datatype;

ALTER TABLE <table_name>

DROP COLUMN <column_name>;

ALTER TABLE <table_name>

MODIFY COLUMN <column_name> datatype;

ALTER TABLE <table_name>

RENAME TO <new_table_name>;

DQL — Data Query Language

DQL command are query commands which are used to retrieve data from the database.

Most used DQL command is SELECT command

  • SELECT - it is used to select a particular data from the table.

Various condition can be specified with the select command. We will look into that in another blog.

SELECT * FROM<table_name>;

SELECT <column_name1>, <column_name2>, …

FROM <table_name>;

_‘*’ operator _is used for selecting all the columns from a table.

#database #rdbms #sql #mysql

STRUCTURED QUERY LANGUAGE (SQL)
2.95 GEEK