generated from jackyzha0/quartz
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affected files: content/.obsidian/plugins/recent-files-obsidian/data.json content/.obsidian/workspace.json content/postgresql/PostgreSQL Constraint and Key.md content/postgresql/PostgreSQL Database.md content/postgresql/PostgreSQL Delete.md content/postgresql/PostgreSQL Join.md content/postgresql/PostgreSQL Sequence and UUID.md content/postgresql/PostgreSQL Table.md content/postgresql/PostgreSQL Update.md content/postgresql/PostgreSQL.md
- Loading branch information
Showing
10 changed files
with
267 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
draft: false | ||
date: 2024-05-16 18:19 | ||
tags: | ||
- postgres | ||
--- | ||
|
||
|
||
|
||
```sql | ||
ALTER TABLE person ADD UNIQUE (email); | ||
ALTER TABLE person ADD CONSTRAINT unique_email UNIQUE (email); | ||
``` | ||
|
||
```sql | ||
ALTER TABLE person DROP CONSTRAINT person_pkey; | ||
``` | ||
|
||
```sql | ||
ALTER TABLE person ADD PRIMARY KEY (id); | ||
``` | ||
|
||
```sql | ||
ALTER TABLE person ADD CONSTRAINT gender_contraint CHECK (gender = 'Female' OR gender = 'Male'); | ||
``` | ||
|
||
```sql | ||
CREATE TABLE car ( | ||
id BIGSERIAL NOT NULL PRIMARY KEY, | ||
make VARCHAR(100) NOT NULL, | ||
model VARCHAR(100) NOT NULL, | ||
price NUMERIC(19,2) NOT NULL | ||
); | ||
|
||
CREATE TABLE person ( | ||
id BIGSERIAL NOT NULL PRIMARY KEY, | ||
first_name VARCHAR(50) NOT NULL, | ||
last_name VARCHAR(50) NOT NULL, | ||
gender VARCHAR(50) NOT NULL, | ||
date_of_birth DATE NOT NULL, | ||
email VARCHAR(150), | ||
car_id BIGINT REFERENCE car(id), | ||
UNIQUE(car_id) | ||
); | ||
``` | ||
|
||
|
||
```sql | ||
UPDATE person SET car_id = 2 WHERE id = 1; | ||
``` | ||
|
||
|
||
> [!info] References | ||
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
draft: false | ||
date: 2024-05-16 18:17 | ||
tags: | ||
- postgres | ||
--- | ||
|
||
|
||
```sql | ||
DELETE FROM person; | ||
``` | ||
|
||
```sql | ||
DELETE FROM person WHERE id = 1; | ||
``` | ||
|
||
|
||
|
||
|
||
> [!info] References | ||
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
draft: false | ||
date: 2024-05-16 18:17 | ||
tags: | ||
- postgres | ||
--- | ||
|
||
|
||
### JOIN | ||
|
||
```sql | ||
JOIN car ON person.car_id = car.id; | ||
``` | ||
|
||
```sql | ||
SELECT person.first_name, car.make, car.price | ||
FROM person | ||
JOIN car ON person.car_id = car.id | ||
``` | ||
|
||
```sql | ||
SELECT person.first_name, car.make, car.price | ||
FROM person | ||
LEFT JOIN car ON person.car_id = car.id | ||
``` | ||
|
||
```sql | ||
SELECT person.first_name, car.make, car.price | ||
FROM person | ||
JOIN car USING (car_uid) | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
> [!info] References | ||
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
draft: false | ||
date: 2024-05-16 18:15 | ||
tags: | ||
- postgres | ||
--- | ||
|
||
### BIGSERIAL | ||
|
||
```sql | ||
ALTER SEQUENCE person_id_seq RESTART WITH 0; | ||
``` | ||
|
||
### UUID | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
> [!info] References | ||
> - [Learn PostgreSQL Tutorial - Full Course for Beginners (youtube.com)](https://www.youtube.com/watch?v=qw--VYLpxG4) | ||
> - [Universally unique identifier - Wikipedia](https://en.wikipedia.org/wiki/Universally_unique_identifier) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.