What is SQL?
SQL (Structured Query Language) is a programming language designed to manage and manipulate relational databases. It is used to communicate with relational database management systems (RDBMS) like MySQL, Oracle, Microsoft SQL Server, and PostgreSQL.
SQL provides a set of commands that allow users to create, modify, and delete database objects such as tables, views, and stored procedures. It also provides commands to query and manipulate data stored in the database.
SQL consists of several parts, including Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL).
Some of the common SQL commands include:
- SELECT: used to retrieve data from one or more tables
- INSERT: used to insert data into a table
- UPDATE: used to modify data in a table
- DELETE: used to delete data from a table
- CREATE: used to create a new database object
- ALTER: used to modify the structure of an existing database object
- DROP: used to delete an existing database object
SQL is a fundamental skill for database administrators, data analysts, data scientists, and developers who work with relational databases.

Step-by-Step to learn SQL Programming
What is database?
A database is a structured collection of data that is organized in a way that enables efficient storage, retrieval, and manipulation of information. It can be thought of as a digital filing system, where data is organized and stored in a logical and coherent manner. Databases are used in a wide range of applications, such as online shopping, banking, healthcare, education, and more. They can be used to store various types of data, including text, images, videos, and numerical data.
There are various types of databases, such as relational databases, NoSQL databases, object-oriented databases, and graph databases. Each type of database has its own strengths and weaknesses, and is suitable for different use cases. Relational databases, for example, are the most commonly used type of database and are based on a set of tables with rows and columns. NoSQL databases, on the other hand, are designed for handling unstructured data and can be used for big data applications.
What is DBMS?
DBMS stands for Database Management System. It is a software system that allows users to create, maintain, and manage databases. DBMS provides an interface between the user and the database, allowing users to perform various operations on the database, such as creating tables, inserting, updating, and deleting data, and querying the database to retrieve information. DBMS is designed to ensure the consistency, accuracy, and security of data within a database. It provides various features and functionalities, such as data backup and recovery, concurrency control, and data integrity constraints, to ensure the reliability of data.
There are various types of DBMS available, such as relational, object-oriented, and NoSQL DBMS. Relational DBMS is the most commonly used type of DBMS, and it is based on a relational model that uses tables to store data. Object-oriented DBMS, on the other hand, is designed to store complex data structures, and NoSQL DBMS is designed to handle unstructured data. DBMS is widely used in various applications, such as banking, healthcare, e-commerce, and social media, where large amounts of data need to be stored, managed, and accessed efficiently.
What are types of DBMS?
There are several types of DBMS, each designed to handle different types of data and workloads. The most common types of DBMS are:
- Relational DBMS: This type of DBMS is based on the relational model and uses tables to store data. Data is organized into rows and columns, and relationships between tables are defined through primary and foreign keys. Examples of relational DBMS include Oracle, MySQL, Microsoft SQL Server, and PostgreSQL.
- Object-oriented DBMS: This type of DBMS is designed to store and manage complex data structures, such as objects, classes, and inheritance hierarchies. Examples of object-oriented DBMS include ObjectStore and Objectivity/DB.
- NoSQL DBMS: This type of DBMS is designed to handle unstructured and semi-structured data, such as text, images, and videos. Unlike relational DBMS, NoSQL DBMS does not use tables to store data, but rather document-oriented or graph-based structures. Examples of NoSQL DBMS include MongoDB, Cassandra, and Neo4j.
- Graph DBMS: This type of DBMS is designed to handle data that has complex relationships and connections, such as social media networks and knowledge graphs. Data is represented as nodes and edges in a graph, and queries are based on graph theory concepts. Examples of graph DBMS include Neo4j, OrientDB, and ArangoDB.
- Hierarchical DBMS: This type of DBMS organizes data in a hierarchical structure, where each record has a parent-child relationship with other records. This type of DBMS is rarely used today, but it was popular in the 1960s and 1970s. Examples of hierarchical DBMS include IBM’s Information Management System (IMS) and ADABAS.
- Network DBMS: This type of DBMS organizes data in a network structure, where each record can have multiple parent and child records. This type of DBMS is also rarely used today, but it was popular in the 1970s and 1980s. Examples of network DBMS include Integrated Data Store (IDS) and Model 204.
How to create database in MySQL RDBMS?
To create a database in MySQL RDBMS, you can follow these steps:
- Open the MySQL command-line interface. This can be done by typing “mysql -u root -p” on the terminal or command prompt and entering your MySQL root user password.
- Type the following command to create a new database:
create database test_db;
Replace “test_db” with the name you want to give to your database.
- To verify that the database has been created, type the following command:
SHOW DATABASES;
This will display a list of all the databases on the MySQL server, including the one you just created.
How to create table in MySQL RDBMS?
To create a table in MySQL RDBMS, you can follow these steps:
- Open the MySQL command-line interface. This can be done by typing “mysql -u root -p” on the terminal or command prompt and entering your MySQL root user password.
- Select the database where you want to create the table. If you just created a new database, you can select it using the following command:
USE test_db;
Replace “mydatabase” with the name of the database you created.
- To create a new table, use the “CREATE TABLE” command. For example, to create a table named “employees” with columns for employee ID, name, gender and salary, you can use the following command:
create table employees(emp_id int, emp_name varchar(100), emp_gender char(1), emp_salary float);
This will create a table named “employees” with three columns: “id”, “name”, “gender”, and “salary”.
To verify that the table has been created, you can use the following command:
DESCRIBE employees;
This will display the structure of the “employees” table, including the column names, data types, and any constraints.
That’s it! You have now created a new table in MySQL RDBMS. You can start inserting data into the table using the “INSERT INTO” command.
How to insert data into above employees table in MySQL RDBMS?
To insert data into the “employee” table that you just created, you can use the following command:
INSERT INTO employee (emp_id, emp_name, emp_gender, emp_salary) VALUES (1, 'John Doe', 'M', 50000.00);
This command inserts a single row of data into the “employee” table with the values specified in the parentheses. You can replace the values with your desired data for each column.
If you want to insert multiple rows in a single command, you can separate each set of values with commas, like this:
INSERT INTO employee (emp_id, emp_name, emp_gender, emp_salary) VALUES (1, 'John Doe', 'M', 50000.00), (2, 'Jane Smith', 'F', 60000.00), (3, 'Bob Johnson', 'M', 55000.00);
This command inserts three rows of data into the “employee” table with the values specified in the parentheses for each set of values.
How to select or fetch or get or retrieve data from employees table in MySQL RDBMS?
To select data from the “employee” table that you created, you can use the following command:
SELECT * FROM employee;
This command selects all columns and rows from the “employee” table and displays them in the result set. You can also specify specific columns to select, like this:
SELECT emp_name, emp_salary FROM employee;
This command selects only the “emp_name” and “emp_salary” columns from the “employee” table and displays them in the result set.
Additionally, you can use the WHERE clause to filter the results based on a specific condition, like this:
SELECT * FROM employee WHERE emp_gender = 'M';
This command selects all columns and rows from the “employee” table where the “emp_gender” column has the value of ‘M’.
How to select data from employees table in MySQL RDBMS?
To update data in the “employee” table, you can use the UPDATE command along with the SET clause to specify the new values and the WHERE clause to filter the rows to be updated based on a specific condition. Here’s an example command:
UPDATE employee SET emp_salary = 55000.00 WHERE emp_id = 1;
This command updates the “emp_salary” column to the value of 55000.00 for the row where the “emp_id” column has the value of 1.
You can also update multiple columns in a single command, like this:
UPDATE employee SET emp_salary = 60000.00, emp_gender = 'F' WHERE emp_id = 2;
This command updates the “emp_salary” column to the value of 60000.00 and the “emp_gender” column to ‘F’ for the row where the “emp_id” column has the value of 2.
Be careful when using the UPDATE command since it can modify multiple rows at once if the WHERE clause is not specific enough. Always make sure to test the command on a small subset of data before running it on a large dataset.
How to delete data from employees table in MySQL RDBMS?
To delete data from the “employee” table, you can use the DELETE command along with the WHERE clause to filter the rows to be deleted based on a specific condition. Here’s an example command:
DELETE FROM employee WHERE emp_id = 1;
This command deletes the row from the “employee” table where the “emp_id” column has the value of 1.
If you want to delete all rows from the table, you can use the following command:
DELETE FROM employee;
This command deletes all rows from the “employee” table, effectively emptying it. Be careful when using the DELETE command since it permanently removes data from the table and cannot be undone. Always make sure to test the command on a small subset of data before running it on a large dataset.