Chapter 7 SQL
Chapter 7 SQL
);
DML COMMAND
SELECT P_CODE, P_DESCRIPT, P_INDATE, P_QOH, P_MIN, P_PRICE, P_DISCOUNT, V_CODE FROM
PRODUCT;
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE FROM PRODUCT
WHERE V_CODE = 21344;
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECT P_DESCRIPT, P_QOH, P_PRICE, V_CODE FROM PRODUCT
WHERE V_CODE <> 21344;
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECT P_DESCRIPT, P_QOH, P_MIN, P_PRICE FROM PRODUCT
WHERE P_PRICE <= 10;
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE
FROM PRODUCT
WHERE V_CODE = 21344 OR V_CODE = 24288;
SELECTING ROWS WITH
CONDITIONAL RESTRICTIONS
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE
FROM PRODUCT
WHERE P_PRICE < 50 AND P_INDATE > '15-Jan-2016';
COPYING PARTS OF TABLES
SQL provides another way to rapidly create a new table based
on selected columns and rows of an existing table.
In this case, the new table will copy the attribute names, data
characteristics, and rows of the original table.
CREATE TABLE PART AS
The SQL command just shown creates a new PART table with
PART_CODE, PART_ DESCRIPT, PART_PRICE, and
V_CODE columns.
In addition, all of the data rows for the selected columns will be
copied automatically.
However, note that no entity integrity (primary key) or
referential integrity (foreign key) rules are automatically
applied to the new table.
In the next slide, you will learn how to define the PK to enforce
entity integrity and the FK to enforce referential integrity.
COPYING PARTS OF TABLES
ALTER TABLE PART ADD PRIMARY KEY
(PART_CODE);
ALTER TABLE PART ADD FOREIGN KEY (V_CODE)
REFERENCES VENDOR;
Alternatively, if neither the PART table’s primary key nor its
foreign key has been designated, you can incorporate both
changes at once:
ALTER TABLE PART ADD PRIMARY KEY
(PART_CODE) ADD FOREIGN KEY (V_CODE)
REFERENCES VENDOR;
UPDATE – UPDATING TABLE
ROWS
If more than one attribute is to be updated in the row, separate the corrections
with commas:
Special Operators
Special Operators
Special Operators
IN is used to check whether an attribute value matches a value contained
within a (sub)set of listed values.