Vous êtes sur la page 1sur 1

1.

Create foreign key

CREATE TABLE CUSTOMER


(
DUMMY VARCHAR2 (2) FOREIGN KEY REFERENCES AGENT(DUMMY) ON DELETE CASCADE
);

2. Insert data from other table

INSERT INTO CUSTOMER


SELECT DUMMY, C_ID
FROM AGENT;

3. Insert certain information into table

INSERT INTO CUSTOMER(C_ID, DUMMY)


VALUES(‘4’,’BLA BLA BLA’);

4. Change current data

UPDATE CUSTOMER
SET DUMMY_ID = 3,DUMMY = 4
WHERE DUMMY = 5;

5. Only alter, drop and create require ‘table’


6. Delete a row from table

DELETE FROM CUSTOMER


WHERE DUMMY_ID > 5 AND DUMMY = 4;

7. Insert a column in table

ALTER TABLE CUSTOMER


ADD (C_ID NUMBER(8,4) PRIMARY KEY);

8. Listing information

SELECT FROM CUSTOMER


WHERE C_NAME LIKE ‘H%’;  depends on the search type

9. Listing information (require arithmetic calculation)

SELECT DISTINCT C_ID, SUM(WORK) AS TOTAL_OF_WORK, AVG(MONEY) AS AVERAGE_OF_MONEY


FROM CUSTOMER
GROUP BY C_ID;

10. Nested selection

SELECT * FROM CUSTOMER


WHERE SALARY > (SELECT MIN(SALARY) FROM AGENT)
GROUP BY SALARY
HAVING SALARY > 10  more or less same restriction function as WHERE
ORDER BY SALARY DESC;

11. Joining database table

SELECT C_ID,C_NAME,C_DATA,A_ID,A_NAME,A_DATA
FROM CUSTOMER, AGENT
WHERE CUSTOMER.C_ID = AGENT.A_ID;

12. SELECT INTO FROM – copy data from 1 table to new table (the new table will be created after the command is run)
13. INSERT INTO SELECT FROM – copy data from 1 or more table to existing table
14. Entity Integrity – every primary keys are unique, not null
(make the foreign key to be properly reference to other table)
15. Referential integrity – every foreign key can be null, but non-null value must be reference to valid primary key
(prevent invalid entry for foreign key, make the parent table impossible to delete the row as long as the row is
referenced by other table)

Vous aimerez peut-être aussi