SQL (1) - 241105 - 150950
SQL (1) - 241105 - 150950
All the SQL statements start with any of the keywords like
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE and
all the statements end with a semicolon (;).
Syntax
The basic syntax for inserting data into a table can be given with:
Here the column1, column2,..., etc. represents the name of the table
columns, whereas the value1, value2,..., and so on represents the
corresponding values for these columns.
Adding Records to a Table
INSERT INTO persons (name, birth_date, phone) VALUES ('Peter
Wilson', '1990-07-15', '0711-020361');
The SELECT statement is used to select or retrieve the data from one or
more tables.
You can use this statement to retrieve all the rows from a table in one go,
as well as to retrieve only those rows that satisfy a certain condition or a
combination of conditions.
Syntax
The basic syntax for selecting the data from a table can be given with:
However, if you want to fetch the values of all the columns available in a
table, you can just use the following syntax:
Syntax
The WHERE clause is used with the SELECT statement to extract only
those records that fulfill specified conditions. The basic syntax can be
given with:
The following command removes all the rows from the employees table:
Similarly, you can delete a database using the DROP DATABASE statement.
SQL Joining Tables
SQL INNER JOIN Operation
SELECT t1.emp_id, t1.emp_name, t1.hire_date, t2.dept_name
FROM employees AS t1 INNER JOIN departments AS t2
ON t1.dept_id = t2.dept_id ORDER BY emp_id;
SQL LEFT JOIN Operation
SQL RIGHT JOIN Operation
SQL FULL JOIN Statement
SQL CROSS JOIN Operation
The UNION operation eliminates the duplicate rows from the combined
result set, by default. That's why the above query returns only 9 rows,
because if you notice the name "Martin Blank" appears in both the
employees and customers tables.
However, if you want to keep the duplicate rows you can use the ALL
keyword, as follow:
SQL LIKE Operator
SQL ALTER TABLE Statement
Adding Constraints
SQL Aliases
SQL GROUP BY Clause
SQL HAVING Clause
SQL CREATE VIEW Statement
Suppose that you want retrieve the id and name of the employees
along with their department name
//we can execute either using Execute statement or
B using PL/SQL Block
//Execute statement
//PL/SQL block
Example