SQL Commands You Should Know

Top 10 SQL Commands You Should Know

There is an increasing demand for developers to efficiently use databases to handle the continuously expanding amounts of data that businesses and organisations are dealing with. The programming language known as SQL, or Structured Query Language, is used to manage data that is kept in relational databases (a popular type of database).

A developer can use SQL commands to build tables, update the data in those tables, search the database, and more. Ten fundamental SQL commands that are a requirement for developers working with SQL will be covered in this article. You can find a code snippet and a brief explanation of what each SQL command does.

A database is used by every large or dynamic website in some capacity, and when combined with Structured Query Language (SQL), the possibilities for data manipulation are virtually limitless.

CREATE TABLE

CREATE TABLE table_name ( column_1 datatype_1, column_2 datatype_2, column_3 datatype_3 );

A new database or table can be created with this command; the previous example adds a new table with a title and column names.

CREATE TABLE table_name(
column1 datatype
column2 datatype,
column3 datatype,
…..
columnN datatype,
PRIMARY KEY( columnName )
);

Let’s utilise this syntax to make a table that contains information on employees for a business.

use mySchema;
CREATE TABLE employee(
empID int not null,
empName varchar(25) not null,
emailID varchar(25) not null,
PRIMARY KEY (empID)
);

 

ALTER TABLE

ALTER TABLE table_name
ADD column_name datatype;

Use this command to change the database’s structure—rather than its contents—for example, to add a new column to a table with a certain datatype.

DELETE

DELETE FROM table_name
WHERE some_condition = some_value;

Using the WHERE keyword, this command can delete data from your database based on certain criteria.

Delete is used to remove records entirely; it can be quite damaging if used in the wrong manner.

The delete command is used to completely delete records, but if it’s used improperly, it might cause significant damage.

 

DELETE FROM people WHERE name = ‘Mahesh’;

DROP

DROP TABLE table_name;

The DROP command deletes a database or table similarly to the create command. Use caution while executing this command because it will completely erase your table, including all of its data, indexes, and other elements.

ALTER TABLE table_name DROP COLUMN column_name;

The above ALTER TABLE and DROP instructions will remove a specific column from a table.

 

INSERT INTO


INSERT INTO table_name (column_1, column_2, column_3)
VALUES (value_1, value_2, value_3);

The INSERT INTO command can be used to add new records to your table. On one or more rows, you can use this command.

SELECT

SELECT column_name
FROM table_name;

SELECT is the first word in every query; it is used to retrieve data from your database. The most basic SQL query is that one. The keywords FROM, WHERE, and ORDER BY can be used after the SELECT statement to define a table, select with conditions, and sort your results, respectively.

UPDATE

UPDATE table_name
SET some_column = some_value
WHERE some_column = some_value;

With this command, you can modify the data in your table by changing it in accordance with the criteria listed behind the WHERE keyword.

AS

SELECT column_name AS ‘Alias’
FROM table_name;

When referring to a column or table, you can utilise a temporary alias by using the AS keyword.

COUNT

SELECT COUNT(column_name)
FROM table_name;

Add the total number of rows where the provided column is not NULL using the COUNT() method.

BETWEEN

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

10 steps to start career in data science 5 Data Analytics Projects for Beginners 5 Excel Data Analysis Functions You Need to Know 5 Things in Your Resume from Getting Your First Job in Data Science Best Data Analytics training in Dehradun Why to learn Best Data science Training in Dehradun Categories of SQL command to know for Data Analysis Data Analyst vs. Business Analyst: What’s the Difference? Data Cleaning With Python for data analytics Data Science Case Studies given by Top Data Scientists