SQL syntax refers to the set of rules that dictate how SQL statements should be written in order to be properly understood and executed by a database management system (DBMS).
Below are some common SQL statements and their basic syntax:
Used for querying data from one or more tables.
SELECT column1, column2, ... FROM table_name WHERE condition;
SELECT column, column2: SELECT Operator used to select the record from Database and `column1, column2` indicates these columns need to return in response.
table_name: The name of the table from which you want to retrieve data.
WHERE condition: An optional clause that allows you to filter the results based on a specified condition
SELECT product_name, product_price FROM products WHERE category = 'GAMES';
The above command will fetch all records from the products table where a category is LAPTOP category.
Used for inserting new records into a table.
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
INSERT INTO: INSERT INTO Operator used to insert a new record in the Database.
INSERT INTO products (product_name, product_price, category) VALUES ('iPad', '$1000', 'tablet');
The above command will Insert new record into products table.
Used to update existing records in a table.
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
SET column1 = value1, column2 = value2: Indicate to update `column1` and `column2` with new values When `WHERE` condition found Truthy.
UPDATE products SET price = 2000 WHERE category = 'LAPTOP';
The above command will update the price of all products in the LAPTOP category to 2000.
Used to delete existing records from the table.
DELETE FROM table_name WHERE condition;
DELETE: DELETE Operator used to delete existing records from the Database.
DELETE FROM products WHERE product_code = 1001;
Note: the record with product_code equal to 1001 will be deleted from the products table.