Cards Flashcards
(74 cards)
Add columns to a table
ALTER TABLE table_name ADD (column_1 column_definition, column_2 column_definition, ... column_n column_definition);
Modify columns in a table
ALTER TABLE table_name MODIFY (column_1 column_type, column_2 column_type, ... column_n column_type);
Delete a column in a table
ALTER TABLE table_name
DROP COLUMN column_name;
Rename a column in a table
ALTER TABLE table_name
RENAME COLUMN old_name TO new_name;
Retrieve data from a table
SELECT expressions
FROM tables
[WHERE conditions];
Insert a single record in a table
- INSERT statement with VALUES keyword
INSERT INTO table
column1, column2, … column_n
VALUES
(expression1, expression2, … expression_n );
Insert multiple records a table from another table
- INSERT statement with SELECT keyword
INSERT INTO table (column1, column2, ... column_n ) SELECT expression1, expression2, ... expression_n FROM source_table [WHERE conditions];
Adding multiple rows with a single statement
- Use INSERT ALL
INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;
Update existing records in a table
UPDATE table SET column1 = expression1, column2 = expression2, ... column_n = expression_n [WHERE conditions];
Remove records from a table
DELETE FROM table
[WHERE conditions];
Remove all records from a table
TRUNCATE TABLE [schema_name.]table_name
[ PRESERVE MATERIALIZED VIEW LOG | PURGE MATERIALIZED VIEW LOG ]
[ DROP STORAGE | REUSE STORAGE ] ;
- Not: this cannot be rolled back
Return all rows from multiple tables based on a matching condition
SELECT columns
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
What are the 10 DDL Statements?
CREATE ALTER DROP RENAME TRUNCATE GRANT REVOKE FLASHBACK PURGE COMMENT
- all auto-commit
What are the 5 DML Statements?
SELECT INSERT UPDATE DELETE MERGE
What are the 3 TCL Statements?
COMMIT
ROLLBACK
SAVEPOINT
What are the 8 Main DB objects?
Constraints Indexes Roles Sequences Synonyms Tables Users Views
What is a Schema?
A collection of certain DB objects all owned by a user account.
Non-Schema Objects
Users
Roles
Public Synonyms
Add a new table
CREATE TABLE table_name (column_1 datatype, column_2 datatype, ... column_n datatype);
Add a user
CREATE USER user_name
IDENTIFIED BY password;
Change a user’s password
ALTER USER user_name
IDENTIFIED BY password;
Create a table from an existing table
CREATE TABLE new_table
AS (SELECT * FROM old_table);
- This will copy the records as well if they exist
What are the 5 system variables (pseudo columns)?
SYSDATE CURRENT_DATE SYSTIMESTAMP LOCALTIMESTAMP USER
-these can be directly retrieved from dual
What is the purpose of DDL?
Used to build database objects.