SQL ET POSTGRE 3.7 : Creation of the Actors table

In this video we create the acteur (actor) table. It has five columns, each with its data type. The first is acteur_id as a SERIAL, then a prenom column of type VARCHAR(30), a nom column also VARCHAR(30), a civilite column as CHAR(1) — used to store the gender as M for male and F for female — and finally a date_naissance column of type DATE. Try to recreate the table on your own first, then come back to this video to compare.

Writing the SQL script

Go back into the film database, open Create Script and start with a comment to structure your script. As before, type CREATE TABLE acteur, open a parenthesis and close the query with a semicolon — every SQL query ends with a semicolon so PostgreSQL knows it is complete. Inside, declare the columns one per line and remember to use commas between them.
CREATE TABLE acteur (
  acteur_id SERIAL PRIMARY KEY,
  prenom VARCHAR(30),
  nom VARCHAR(30),
  civilite CHAR(1),
  date_naissance DATE
);
  • Same naming and types as in the video to keep the next inserts working.
  • If you got it wrong, use DROP TABLE acteur; and recreate the table cleanly.
  • Always verify with SELECT * FROM acteur;.
Select the query and run it — the query is successful. Verify with SELECT * FROM acteur; and you should see the acteur table with each column you defined. Important: keep the same column names and data types as in the video, because the next lessons will insert data that depends on them. If you used different names, drop the table with DROP TABLE acteur; (be careful with the table name so you do not lose anything else) and recreate it exactly as shown.

Summary

This lesson teaches how to create an actors table in PostgreSQL with five columns: id (serial primary key), first name (varchar 30), last name (varchar 30), gender (char 1 for M/F), and date of birth (date type). The instructor demonstrates the complete CREATE TABLE syntax, verifies the table structure using SELECT, and covers error recovery by using DROP TABLE and recreating if needed to ensure column names and data types match the expected schema.

Key points

  • Define table structure using CREATE TABLE with proper column naming and data types (serial for IDs, varchar for text fields with length limits, char for single characters, date for birth dates)
  • Use PRIMARY KEY constraint on the id column to ensure each actor record is uniquely identifiable
  • Verify successful table creation by running SELECT * FROM actors to display all columns and confirm the schema matches the design
  • Maintain consistency with column names and data types for future INSERT operations and queries to function correctly
  • Use DROP TABLE if corrections are needed to remove and recreate the table with the correct structure

FAQ

What are the five columns in the actors table and their data types?

The actors table contains: id (serial), first name (varchar 30), last name (varchar 30), gender/civility (char 1 for M/F), and date of birth (date type).

Why is it important to use PRIMARY KEY on the id column?

The PRIMARY KEY constraint ensures each actor record is uniquely identifiable and prevents duplicate id values, maintaining data integrity in the database.

What should you do if you create the table incorrectly?

Use DROP TABLE actors to remove the incorrect table, then recreate it with the correct column names and data types to avoid conflicts with subsequent INSERT operations.