





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






TRUNCATE TABLE✔✔delete all data from table leaving structure intact
DROP TABLE✔✔deletion of a table
DELETE FROM table_name WHERE conditional;✔✔delete specific data/rows from a table
DROP DATABASE✔✔Dropping a database
ALTER TABLE table_name ALTER COLUMN column_name TIMESTAMP DEFAULT current_timestamp;✔✔adding column in table to store a timestamp
ALTER TABLE table_name ALTER COLUMN column_name TYPE CHARACTER VARYING( ), ALTER COLUMN column_name SET NOT NULL;✔✔modify a column in table using ALTER command
ALTER TABLE CHEESES ADD COLUMN description TEXT NOT NULL DEFAULT 'screwed'; ALTER TABLE CHEESES ALTER COLUMN description DROP DEFAULT;✔✔add column to table and be a multi-lined text field that IS required.
COMMENT ON TABLE table_name IS 'your text here';✔✔adding a comment to a table
INSERT INTO test2 (name, id) SELECT name, id FROM test WHERE name > 'm';✔✔insert data from one table to another
INSERT INTO table_name1 (make, model, year) SELECT * FROM table_name WHERE make = 'Alfa Romeo';✔✔copy data from one table to another
ALTER TABLE table_name ADD COLUMN column_name✔✔adding column in a table
ALTER TABLE Pass_keys ALTER COLUMN pass_key TYPE BYTEA USING(pass_key::bytea), ALTER COLUMN pass_key SET NOT NULL;✔✔modify column in a table
ALTER TABLE Pass_keys ALTER COLUMN pass_key TYPE BYTEA USING(pass_key::bytea); COMMENT ON COLUMN Pass_keys.pass_key IS 'id of employees';✔✔modify column in a table including a comment
ALTER TABLE UC_project DROP COLUMN P_budget; ALTER TABLE UC_project ADD COLUMN P_cost INT NOT NULL DEFAULT 0; ALTER TABLE UC_project ALTER COLUMN P_cost DROP DEFAULT;✔✔delete one column in table and modify 2nd w/required INT
UPDATE table_name SET orderQty = 10 WHERE orderID = 1;✔✔update data in table
DELETE FROM and TRUNCATE TABLE✔✔2 commands to delete table data w/o deleting table
\d✔✔command to display table structures
CREATE TABLE Cipher_keys ( id BIGSERIAL PRIMARY KEY, name VARCHAR(32) NOT NULL, cipher_key text );✔✔Create a table named Cipher_keys to store encryption keys for the data center model. table should have the following data: Automatically generated integer primary key (id) The name of the key up to a length of 32 (required, name) Multi-line text field for the key (cipher_key)
ALTER TABLE Things DROP COLUMN color;✔✔deleting column from a table
returns ALL rows (including duplicates) from 2 or more tables only where records/Rows appear in both tables/queries/sets✔✔INTERSECT ALL operator
Returns a distinct (non repeating) list of Rows that Only appear in the Left Query/Table/Top result set. works like the Oracle MINUS set operator✔✔EXCEPT operator
Returns a list of Rows and duplicate Rows that Only appear in the Left Table/Query✔✔EXCEPT ALL operator
keyword that includes/shows duplicate rows✔✔ALL
Eliminates all duplicate records and fetches only unique records.... keyword used after set operator to specify duplicate Rows should Not be included - which is also the default behavior✔✔DISTINCT
establish temporary tables by using the WITH clause✔✔Common Table Expressions
Returns every possible combination of rows from the first table and the second table✔✔cross join
Returns only the records that have matching values in the joined field of two tables✔✔inner join
Returns all the records from the first table and only matching records from the second table✔✔left outer join
Returns all the records from the second table and only matching records from the first table✔✔right outer join
allows you to list any number of columns and scalar values - if first value in list is NULL it will try and fill it in with the next value✔✔COALESCE function
A 2 value function returning NULL if the 1st value equals the 2nd value✔✔NULL IF function
each function takes Any number of values and returns the Least or Greatest of the values, respectively✔✔LEAST/GREATEST
changing the data type of a column -- column :: datatype✔✔Casting
used to determine the unique values in a column or group of columns✔✔DISTINCT
ensures that only one Row is returned where one or more columns are unique in the set✔✔DISTINCT ON
allows a query to map various values in a column to other values✔✔CASE WHEN
Returns ALL Rows from 2 or more tables regardless of whether the join condition is met✔✔Full Join
the number of digits in the Field✔✔Precision
the number of digits to the right of the decimal point✔✔Scale
an exact quantity and the Precision and Scale can be specified✔✔Numeric
a whole number with no fractional or decimal component✔✔Integer
an inexact numeric type with varying degrees of precision which may vary depending on specific type indicated✔✔Floating Point
REAL, DOUBLE PRECISION, FLOAT✔✔Floating Point types
REAL floating point✔✔6 digit decimal precision
DOUBLE PRECISION floating point✔✔15 digit decimal precision
FLOAT floating point✔✔SQL-standard notation specifying an inexact numeric type
Advantages of SQL Databases✔✔Intuitive, Efficient, Declarative, Robust
Filters single rows. Specifies condition while fetching data from tables. Conditional logic that limits amount of data returned.✔✔WHERE
returns true if a NULL value found, otherwise returns false✔✔IS NULL
Sets upper limit on number of tuples/Rows returned by SQL✔✔LIMIT
Specifies database tables of views involved in SELECT statement✔✔FROM
ANALYZE✔✔collects statistics about tables/indices(indexes) and stores them in internal tables
CREATE INDEX I_Name ON Employees(last_name);✔✔example of creating an Index:
DROP INDEX fix_Email ON Customers;✔✔example of dropping an Index:
Allows SQL interpreter to do nothing for next defined time period✔✔pg_sleep command...
causes interpreter to end a query specified by process ID(pid)✔✔pg_cancel_backend command
Extract, Transform, Load: used to standardize data across systems, allowing it to be queried✔✔"ETL
used to concantonate or join together to column items such as a first and last name.✔✔CONCAT
default to a result listing is it Ascending or Descending?✔✔Descending
specifies database username in psql command✔✔-u
common term for displaying output in a command line terminal environment... printed rather than saved to file. (standard out)✔✔TO STDOUT
CSV✔✔indicates a CSV file format for copying data to...
indication to print out the Header as well with the COPY command✔✔HEADER
Not always fastest/most efficient scan but will Always produce correct result. Using SELECT in database executes one automatically✔✔Sequential Scan
optimizes variables within a request with aim to reduce execution time✔✔Query Planning
command for running SQL server from command prompt - preceeds code✔✔c:>psql sqlda
pre-processing step is executed before search of database records can occur to improve performance of database queries✔✔Index Scanning
a type of Binary search tree. a self-balancing structure maintaining it's own data structure for efficient searching✔✔B-tree Indexes
not recommended index for use as limited in PostgressSQL though just accepted✔✔Hash Index
used to get list of functions available in memory in PostgreSQL✔✔\df command
Used to review the function definition for already defined functions in PostgreSQL✔✔\sf command
changes and edits commands respectively in PostgreSQL✔✔\cd and \ed commands
known as callbacks or events in other languages. triggers execution of SQL statements/function in response to a specific event✔✔Triggers
used to repeat/modify statements or queries without re-entering the statement each time or searching for it's use in longer code segments✔✔Functions
SQL Advantages:✔✔Intuitive Efficient Declarative Robust
ACID✔✔Atomocity, Consistency, Isolation, Durability
Basic Data Types:✔✔Numeric, Character, Boolean, DateTime, Data Structures
3 (4) most common ETL transformations:✔✔Aggregation, Deduplication, filtering/data cleaning, data conversion
ETL stages:✔✔Stage the data, Clense/organize data, Deliver/data presented
single value/row subquery for SELECT, FROM, WHERE:✔✔uses operators (+, -, <, >, =, etc.)