Create a Postgres Table

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

Learn how to create a table using the most widely-used data types (serial, varchar, integer, float, boolean, and date), and the most necessary constraints (NOT NULL and primary key).

[00:01] We're going to start with a Create Table statement and Create Directors table, some movie directors for us. Nice ID column here. Serial says that it's going to be auto-incrementing, so it would go one, two, three automatically. We don't have to worry about that.

[00:17] We'll get a name for our directors. This is going to be a string up to 200 characters long. We can just see here that the directors table is in fact created. There's no data in it. Name, ID -- that's what we expect to see.

[00:33] Directors don't really matter unless we have movies. Let's give it another ID column. We've seen that before. Again, these are kind of arbitrary. We'll give it a title. We probably want the title to be there, so we're going to say that it's not null. It can never be null.

[00:53] Let's give it a release date. We haven't seen the date definition before. It's going to be the number of stars they can have, maybe one, two, three, four, five. Let's give it a director ID to reference the directors table.

[01:09] We saw directors before. Let's see movies. There we go. A little empty table. That's what we expect.

[01:16] Just for good measure, I'm going to insert some data here. Don't worry about what these things say. I just want to take a look at what this means to have some data in our tables now, so we can have a sense of what these tables are about.

[01:29] Now we have our directors table up here. We see IDs were inserted for us, because we only inserted some names up here. The same thing happens for us down here in the movies table. We inserted a couple movies, and this is what those tables look like when we fill in some more data.

Brett Cassette
Brett Cassetteinstructor
~ 7 years ago

For anyone wondering more about setting up dev environment:

Check out the course Github

Kartikey Tanna
Kartikey Tanna
~ 7 years ago

You can use pgAdmin if you are on Windows

Brett Cassette
Brett Cassetteinstructor
~ 7 years ago

Thanks for helping people out Kartikey :)

Brendan Whiting
Brendan Whiting
~ 7 years ago

Can someone suggest a tutorial for getting set up with a database and hooking it up with the Postgres client? I downloaded the software but I don't know what to do next. In other words I'm looking for what I need to do to get ready for the first video in the series.

Brett Cassette
Brett Cassetteinstructor
~ 7 years ago

You can read the README on Github

Brendan Whiting
Brendan Whiting
~ 7 years ago

Awesome thx

Taeshik Hwang
Taeshik Hwang
~ 7 years ago

What is the program name that you use for postgresql in this lecture? I don't know what it is, so i can't start your lecture.

Taeshik Hwang
Taeshik Hwang
~ 7 years ago

What is the program name that you use for postgresql in this lecture? I don't know what it is, so i can't start your lecture.

Sorry I checked the reply above.

Lucas
Lucas
~ 7 years ago

Seems that someone felt offended by my previous comment and was deleted. So I'm re asking it: Is there any particular reason why all the videos are so fast paced? If so, what's the purpose on that? Feels that the author has taken for granted a lot of knowledge that audience is supposed to have (if that's the case there's absolutely no point in taking this course as you probably know most of it). On the other side if you're just new to a relational engine you will be absolutely confused (too many concepts terribly exposed and explained) as it does not have a clear goal in any section, it feels like a bad SQL medley. I'm not new to SQL and took this course just to remind a few things but completely failed that purpose.

Serge Bedzhik
Serge Bedzhik
~ 6 years ago

A little typo in the transcript. I think it should be "release_date" not "releas_date". Thanks.

Loïc
Loïc
~ 5 years ago

You can use pgAdmin if you are on Windows Or linux (ubuntu etc)

Nenad
Nenad
~ 5 years ago

Also dbeaver community edition is looking very good. https://dbeaver.io/

Markdown supported.
Become a member to join the discussionEnroll Today