
For an instructor lead, in-depth look at learning SQL click below.
Welcome to this beginner’s guide to Structured Query Language, commonly known as SQL. This post will focus on the basics of database querying using SQL, one of the most widely used database management languages. By the end, you’ll have a solid foundation on which to build your SQL knowledge and skills.
What is SQL?
SQL is a standard language designed for managing data in relational database management systems. It’s used to communicate with databases and perform tasks like data retrieval, insertion, updation, and deletion in a database.
Database Structure
A database is organized into tables, each table consists of rows and columns. Columns represent information types such as names, emails, etc., while rows represent data entries for those information types.
Basics of SQL Syntax
Now we’ll go through some of the core commands and concepts of SQL.
SELECT
The first command that everybody learns when they start with SQL is SELECT. It is used to select data from a database.
1 2 3 |
SELECT * FROM Customers; |
This particular query is saying: select all records from the table ‘Customers’.
WHERE
This is used to filter records, and is used to extract only those records that fulfill a specified condition.
1 2 3 |
SELECT * FROM Customers WHERE Country='Mexico'; |
This will return all customer data where the customer’s country is Mexico.
INSERT INTO
This statement is used to insert new data into a database.
1 2 3 4 |
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway'); |
Here, a new customer with the given values is inserted into the Customer table.
UPDATE
This command is used to modify existing records in a table.
1 2 3 |
UPDATE Customers SET contactname='Alfred Schmidt', city= 'Frankfurt' WHERE customerID =1; |
This command will update the ‘contactname’ and ‘city’ of the customer record where the customerID is 1.
DELETE
You can use this statement to delete existing records in a table; use it carefully!
1 2 3 |
DELETE FROM Customers WHERE CustomerName='AlfredsFutterkiste'; |
This will delete the customer named ‘AlfredsFutterkiste’ from the Customers table.
Caution:
Be always careful when using DELETE statement without WHERE clause, because it deletes all records in a table.
I hope you find this beginner’s handbook helpful for your journey into SQL and database handling. Stay tuned for more advanced topics.
Remember, practice is key to mastering SQL. Enjoy Querying!
</pre>