DEV Community

Mwenda Harun Mbaabu
Mwenda Harun Mbaabu

Posted on • Updated on

Mastering the Essentials: 10 Fundamental SQL Commands for Beginners

Image description

Are you a budding developer looking to dive into the world of databases and data management? SQL (Structured Query Language) is an indispensable tool that will empower you to interact with databases effectively. Whether you're building web applications, analyzing data, or working with any form of data storage, having a solid grasp of SQL commands is a must.

In this article, we'll introduce you to ten fundamental SQL commands that every beginner should know. These commands will serve as the building blocks of your database journey, allowing you to retrieve, manipulate, and manage data efficiently.

By the end of this guide, you'll have a strong foundation to work with relational databases and handle various data-related tasks. So, let's get started with these essential SQL commands that will unlock a world of possibilities in the realm of data management.

1). SELECT: This command is used to retrieve data from a database. It allows you to specify which columns you want to retrieve and which table(s) to retrieve the data from.

For example:


SELECT first_name, last_name FROM employees;

Enter fullscreen mode Exit fullscreen mode

2). INSERT: The INSERT statement is used to add new rows of data to a table. You specify the table and the values you want to insert into the columns.

For example:


INSERT INTO products (product_name, price) VALUES ('Laptop', 999.99);

Enter fullscreen mode Exit fullscreen mode

3). UPDATE: This command is used to modify existing records in a table. You specify the table, the columns to update, and the new values. You also typically use a WHERE clause to specify which rows to update.

For example:


UPDATE orders SET status = 'Shipped' WHERE order_id = 12345;


Enter fullscreen mode Exit fullscreen mode

4). DELETE: The DELETE statement is used to remove rows from a table based on a specified condition. Be careful when using DELETE as it permanently removes data.

For example:


DELETE FROM customers WHERE customer_id = 5678;


Enter fullscreen mode Exit fullscreen mode

5). CREATE TABLE: This command is used to create a new table in the database. You specify the table name and the columns it will have, along with their data types.

For example:


CREATE TABLE employees (
    employee_id INT,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    hire_date DATE
);

Enter fullscreen mode Exit fullscreen mode

6). ALTER TABLE: The ALTER TABLE command is used to modify an existing table, such as adding, modifying, or dropping columns.

For example, to add a new column:


ALTER TABLE products ADD stock_quantity INT;

Enter fullscreen mode Exit fullscreen mode

7). DROP TABLE: This command is used to delete an entire table and all of its data. Use it with caution, as it cannot be undone.

For example:


DROP TABLE archived_data;

Enter fullscreen mode Exit fullscreen mode

8). WHERE: The WHERE clause is used to filter rows based on a specified condition. It's often used with SELECT, UPDATE, and DELETE statements.

For example:


SELECT * FROM orders WHERE order_status = 'Pending';


Enter fullscreen mode Exit fullscreen mode

9). ORDER BY: The ORDER BY clause is used to sort the result set of a SELECT statement. You specify the column(s) to sort by and whether to sort in ascending (ASC) or descending (DESC) order.

For example:


SELECT * FROM products ORDER BY price DESC;

Enter fullscreen mode Exit fullscreen mode

10). GROUP BY: The GROUP BY clause is used to group rows that have the same values in specified columns into summary rows. It's often used with aggregate functions like SUM, COUNT, AVG, etc.

For example:


SELECT category, COUNT(*) as count FROM products GROUP BY category;

Enter fullscreen mode Exit fullscreen mode

These basic SQL commands should provide a solid foundation for beginners to work with relational databases. As you embark on your journey into the realm of data management, remember that SQL is a language of immense power and versatility. The commands you've learned here are just the beginning. With practice and exploration, you'll find yourself adept at handling complex data tasks and creating robust applications.

So, embrace the world of SQL, dive into databases, and let these fundamental commands be your guiding stars. As you continue to build your skills and explore the depths of data, you'll discover that SQL is an invaluable tool that opens up endless possibilities in the world of technology.

Happy coding!

Top comments (1)

Collapse
 
john_mackonen profile image
John Mackonen

Well explained. Thanks for sharing