SQL BASIC
- The SELECT statement:
The SELECT statement is used to retrieve data from a database. The syntax for the SELECT statement is as follows:
SELECT column_name, column_name
FROM table_name
WHERE condition;
The column_name specifies the name of the column that you want to retrieve data from. You can specify multiple column names by separating them with commas. The table_name specifies the name of the table that you want to retrieve data from. The condition is an optional clause that you can use to filter the data that is returned.
For example, the following SELECT statement will retrieve all of the rows from the customers table:
SELECT *
FROM customers;
The * wildcard character tells SQL to retrieve all of the columns from the table.
- The INSERT statement
The INSERT statement is used to add new rows to a table. The syntax for the INSERT statement is as follows:
INSERT INTO table_name (column_name, column_name)
VALUES (value, value);
The table_name specifies the name of the table that you want to insert data into. The column_name specifies the name of the column that you want to insert data into. You can specify multiple column names by separating them with commas. The value specifies the value that you want to insert into the column.
For example, the following INSERT statement will add a new row to the customers table with the following values:
INSERT INTO customers (name, email)
VALUES (‘John Doe’, ‘johndoe@example.com’);
- THE UPDATE STATEMENT
The UPDATE statement is used to modify existing data in a table. The syntax for the UPDATE statement is as follows:
UPDATE table_name
SET column_name = value
WHERE condition;
The table_name specifies the name of the table that you want to update data in. The column_name specifies the name of the column that you want to update. The value specifies the new value that you want to update the column to. The condition is an optional clause that you can use to filter the rows that are updated.
For example, the following UPDATE statement will update the email address of all customers whose name is John Doe:
UPDATE customers
SET email = ‘johndoe@newemail.com’
WHERE name = ‘John Doe’;
- THE DELETE STATEMENT
The DELETE statement is used to delete rows from a table. The syntax for the DELETE statement is as follows:
DELETE FROM table_name
WHERE condition;
The table_name specifies the name of the table that you want to delete rows from. The condition is an optional clause that you can use to filter the rows that are deleted.
For example, the following DELETE statement will delete all rows from the customers table where the name column is equal to John Doe:
DELETE FROM customers
WHERE name = ‘John Doe’;