Basic SQL commands: SELECT, INSERT, UPDATE, DELETE

Página 11

SQL, or Structured Query Language, is the standard language for manipulating databases. It is a declarative language that allows the creation, manipulation and consultation of data stored in Relational Databases. In this text, we will cover four basic SQL commands: SELECT, INSERT, UPDATE and DELETE.

SELECT

The SELECT command is used to select data from one or more tables. The basic syntax is:

SELECT column1, column2, ..., columnN FROM table_name;

If you want to select all columns, you can use the asterisk (*) character instead of listing all columns. For example:

SELECT * FROM table_name;

You can also use the WHERE clause to filter the results. For example:

SELECT * FROM table_name WHERE column = 'value';

INSERT

The INSERT command is used to insert new records into a table. The basic syntax is:

INSERT INTO table_name (column1, column2, ..., columnN) VALUES (value1, value2, ..., valueN);

For example, if you have a table called 'customers' with columns 'name', 'email' and 'phone', you could insert a new customer as follows:

INSERT INTO customers (name, email, phone) VALUES ('John', '[email protected]', '123456789');

UPDATE

The UPDATE command is used to update existing records in a table. The basic syntax is:

UPDATE tablename SET column1 = value1, column2 = value2, ..., columnN = valueN WHERE condition;

For example, if you want to update the email for customer 'John' in the 'customers' table, you could do the following:

UPDATE clients SET email = '[email protected]' WHERE name = 'John';

It is very important to always use the WHERE clause when using the UPDATE command. If you don't use it, all table records will be updated!

DELETE

The DELETE command is used to delete existing records from a table. The basic syntax is:

DELETE FROM table_name WHERE condition;

For example, if you wanted to delete the customer 'John' from the 'customers' table, you could do the following:

DELETE FROM customers WHERE name = 'John';

As with the UPDATE command, it is very important to always use the WHERE clause when using the DELETE command. If you don't use it, all table records will be deleted!

In summary, SELECT, INSERT, UPDATE and DELETE are basic SQL commands that allow data manipulation in Relational Databases. They are the basis for any database operation and are indispensable for any software developer or database administrator.

Now answer the exercise about the content:

Which of the following SQL commands is used to select data from one or more tables?

You are right! Congratulations, now go to the next page

You missed! Try again.

Next page of the Free Ebook:

12Aggregate Functions in MySQL

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text