Postgresql Flashcards
PostgreSQL
is a database management system that uses SQL to interact with the database
SQL
Standard Structures Query Language
Types of data bases
Relational and non relational
Types of relational databases
- One-to-one relationship
- One-to-Many relationship
- Many-to-Many relationship
Main command types in SQL
- DDL- data definition language
- DCL- data control language
- DML- data manipulation language
DDL commands
Data definition language
- create - create a database, table, temporary user, user
- drop - remove all the data and the structure of column, table and user
- alter - making changes remove, update
- truncate - remove all data in a table
DCL commands
Data control language
Grant - give privileges
Revoke - remove privileges
DML commands
Data manipulation language
- Insert - data in a table
- update - any data in a table
- delete - either while data in data base or certain data from table
- select - retrieve data from table
Inner join
Retuns rows when there is a match in both tables
Full join
Returns all rows when there is a match in one of the tables
Left join
Returns all rows from the left table, and the matched rows from the right table
Right join
Returns all rows from the right table and the matched rows from the left table
What does truncate do
Removes all of the values inside of a table from the database
What does drop do
Remove both the content and the structure of the table, database or user
What is a constrain
Is a rule applied to columns or table in a database to maintain the integrity and accuracy of the data
Types of constraints
Primary key, foreign key, unique, check, not null, default
Data types
- numeric type: int, float, serial
- character type: text, char(50), varchar(50)
- data/time type
- Boolean type
- json
What is alter used for
- add column
- rename column
- remove column
- add constraint
- remove constraint
Distinct formula
Select distinct attributename from tablename;
Limit formula
Select * from tablename LIMIT number;
Aggregate functions formula
Select aggregate(attributename) from tablename;
AVG(), COUNT(), MIN(), MAX(), and SUM().
Ascending, descending formula
Select * from tablename ORDER BY attributename ASC/DESC;
Comparison operators formula
Select * from tablename WHERE attribute operator value;
Arithmetic operators formula
Select attributename operator value from tablename;
Why data validation is important
To ensure that data stored in a database is accurate, consistent and meets the specified standards and business rules.
Formula to find duplicates
Select name, count()
from tablename
group by name
having count() >1;
Formula of joins
Select attribitenames (or*)
from table1
name join table2
on table1.column = table2.column;
Difference between char, varchar and text data types
- char - is fixed length character string
- varchar - is variable length character string
- text - is large variable length character string