SQL Commands – SQL Commands Reference #sql #commands, #sql #command, #sql, #sql #tutorial, #sql #examples,
SQL Commands is a website demonstrating how to use the most frequently used SQL clauses. SQL Commands is not a comprehensive SQL Tutorial, but a simple guide to SQL clauses available online for free.
Our SQL Commands reference will show you how to use the SELECT, DELETE, UPDATE, and WHERE SQL commands. Each of the SQL commands articles is illustrated with practical examples, designed to help you learn the SQL commands syntax. You can also do the SQL practice exercises at the end of each tutorial.
A relational database consists of various database objects including but not limited to tables, views, stored procedures, user-defined functions, and triggers. Let’s have a look at database tables first.
All the information in a database is stored in tables, which are identified by name. Each table consists of rows and columns. Each of the db table columns is identified by name and it has a specific data type. The rows store the information saved in the table. Here is how a simple table looks like:
SQL Command Types
We can divide the SQL commands in several major categories depending on their purpose – Data Definition Language (DDL), Data Control Language (DCL), Data Query Language (DQL), and Data Manipulation Language (DML).
SQL Commands Used to Create, Modify, and Delete database Objects (DDL)
Before we can retrieve or manipulate data we need to create database objects like table so we can store some information there. We can use the DDL command CREATE to create a table:
SQL Commands Used to Manipulate Data (DML)
After we have created our table we can use the INSERT SQL statement (DML) to enter some data in it.
INSERT INTO Cities (CityID, CityName, State) VALUES (1, ‘Los Angeles’, ‘California’) INSERT INTO Cities (CityID, CityName, State) VALUES (2, ‘New York’, ‘New York’) INSERT INTO Cities (CityID, CityName, State) VALUES (3, ‘Chicago’, ‘Illinois’) INSERT INTO Cities (CityID, CityName, State) VALUES (4, ‘Seattle’, ‘Texas’)
In our 4th statement above we made a mistake, and entered ‘Texas’ as a state for Seattle, so we can correct that we another SQL DML command UPDATE:
UPDATE Cities SET State = ‘Washington’ WHERE CityID = 4
We used the WHERE SQL clause to specify that we want to update only the record with CityID of 4. Of course we can decide that we don’t need the Seattle record at all and we can delete it with the following statement:
DELETE FROM Cities WHERE CityID = 4
SQL Commands Used to Retrieve Data (DQL)
One of the most important tasks when working with SQL is retrieving data from database tables. We do that using the SQL SELECT command:
SELECT CItyID, CityName, State FROM Cities
The above SQL command will retrieve all rows from the database table. You can also order the results of your SQL query by one or more columns:
SELECT CItyID, CityName, State FROM Cities ORDER BY State
You can also retrieve data conditionally using SQL WHERE clause:
SELECT CItyID, CityName, State FROM Cities WHERE ID > 2
To learn in more detail about each of the SQL commands above please use the left navigation menu and watch our “Introduction to SQL Commands” video below.