Lab-03, 4
Lab-03, 4
OBJECTIVE
Apply creating and altering tables commands in SQL
THEORY
Creating a Table
When you started this section, you looked at the standard CREATE syntax of:
And then you moved on to a more specific start (indeed, it’s the first line of the
statement that creates the table) and created a table called Customers
SYNTAX
INSERT [INTO] <table>
[(column_list)] VALUES (data_values)
Where:
Table is the name of the table
Column is the name of the column in the table to populate
Value is the corresponding value for the column
INTO is optional and columns list is also optional and may be omitted if you list
values in the default order of the columns in the table.
This result could also have been achieved by using this query if the column order
is default:
Implicit Method: Omit the Column Name From the Column List
Explicit Method: Specify the NULL keyword or empty string (‘ ‘) in the values
insert into department values(70,'Finance',NULL)
list.
Here Bonus table has been populated by a SELECT statement from Employee
table using the INSERT statement. Check the Bonus table by using this query.
a. Consider the following query: Specific row(s) can be updated while using the
WHERE clause.
i. Consider the following query: All rows in the table will be updated, if we
omit the WHERE clause.
Temp table has the same data as of the Employee table. You will be provided this
in the lab.
This changes the department number of all employees in the temp table with that of
the employee number 104 in the Employee table and vice versa his job title.
Syntax
DELETE FROM table
WHERE condition
Here FROM keyword is optional. Always remember that all the rows of the table will
be deleted if not mentioning the WHERE clause.
b. Consider the following query: All rows in the table will be deleted, if we
omit the WHERE clause.
OR Operator
Where Clause
It is used to extract only those records that fulfill a specified criterion.