Basic SQL Interview Questions


What is SQL?

The acronym SQL stands for Structured Query Language. It is the typical language used for relational database maintenance and a wide range of data processing tasks. The first SQL database was created in 1970. It is a database language used for operations such as database creation, deletion, retrieval, and row modification. It is occasionally pronounced “sequel.” It can also be used to manage structured data, which is made up of variables called entities and relationships between those entities.

What is Database?

database is a system that helps in collecting, storing and retrieving data. Databases can be complex, and such databases are developed using design and modelling approaches.

What is DBMS?

DBMS stands for Database Management System which is responsible for the creating, updating, and managing of the database. 

What is RDBMS? How is it different from DBMS?

RDBMS stands for Relational Database Management System that stores data in the form of a collection of tables, and relations can be defined between the common fields of these tables.

How to create a table in SQL?

The command to create a table in SQL is extremely simple:

 CREATE TABLE table_name (
	column1 datatype,
	column2 datatype,
	column3 datatype,
   ....
);

We will start off by giving the keywords, CREATE TABLE, and then we will give the name of the table. After that in braces, we will list out all the columns along with their data types.

For example, if we want to create a simple employee table:

CREATE TABLE employee (
	name varchar(25),
	age int,
	gender varchar(25),
   ....
);

How to delete a table in SQL?

There are two ways to delete a table from SQL: DROP and TRUNCATE. The DROP TABLE command is used to completely delete the table from the database. This is the command:

DROP TABLE table_name;

The above command will completely delete all the data present in the table along with the table itself.

But if we want to delete only the data present in the table but not the table itself, then we will use the truncate command:

DROP TABLE table_name ;

How to change a table name in SQL?

This is the command to change a table name in SQL:

ALTER TABLE table_name
RENAME TO new_table_name;

We will start off by giving the keywords ALTER TABLE, then we will follow it up by giving the original name of the table, after that, we will give in the keywords RENAME TO and finally, we will give the new table name.

For example, if we want to change the “employee” table to “employee_information”, this will be the command:

ALTER TABLE employee
RENAME TO employee_information;

How to delete a row in SQL?

We will be using the DELETE query to delete existing rows from the table:

DELETE FROM table_name
WHERE [condition];

We will start off by giving the keywords DELETE FROM, then we will give the name of the table, and after that we will give the WHERE clause and give the condition on the basis of which we would want to delete a row.

For example, from the employee table, if we would like to delete all the rows, where the age of the employee is equal to 25, then this will be the command:

DELETE FROM employee
WHERE [age=25];

Comments

Popular posts from this blog

🔆Navigating the Skies: Exploring Data Analysis in Aerospace Engineering🔆

Introduction to Natural Language Processing (NLP)

"Mastering Data Visualization with D3.js"