SQL ET POSTGRE 4.20 : Data insertion in our BDD Films

Now that we know how to insert, update and delete data in a table, we are going to populate our film database. Select the film database and open Create Script. To save time, several scripts come with this video so that you can load all the data into your tables without retyping anything.

Loading the scripts

Open the first script — it contains the data for the realisateur (directors) table. Select the INSERT INTO query with all its VALUES, copy it, paste it into pgAdmin and run it. The query succeeds. Verify with SELECT * FROM realisateur and you will see all directors loaded into the table. Repeat the same steps with the next script for the acteur table: copy, paste, run, then check with SELECT * FROM acteur.
-- Load order
1) realisateur
2) acteur
3) film
4) film_acteur (junction)
  • Insert directors first, then actors, then films.
  • Finish with the film_acteur junction table that links films to actors.
  • Always check each table with a SELECT * after the insert.
Move on to the third script for the film table and apply the same workflow. Finally, open the script for the film_acteur junction table, which links film ids to actor ids. Copy, paste, run, then check that everything is in place with a SELECT *. The film database is now populated and ready. From now on, we will use this data to learn how to query, join and aggregate records throughout the course.

Summary

This lesson demonstrates the process of populating a PostgreSQL Films database with sample data using prepared SQL INSERT scripts. The instructor sequentially loads data into four interconnected tables—directors, actors, films, and a film-actors junction table—by copying INSERT statements into PostgreSQL, executing them, and verifying results with SELECT queries. This populated database serves as the foundation for subsequent lessons on joins, subqueries, and data aggregation.

Key points

  • Data insertion uses prepared SQL scripts with INSERT INTO statements to efficiently populate multiple database tables at once.
  • Always verify data insertion by executing SELECT queries to confirm all records were successfully added before proceeding.
  • The film_actors table is a junction table that establishes many-to-many relationships between films and actors using their respective IDs.
  • Insert data in logical order: directors first, then actors, then films, then film-actor relationships to respect foreign key constraints.
  • Sample data loaded in this lesson becomes the working dataset for all subsequent course lessons on data manipulation and querying.

FAQ

What is a junction table and why is film_actors used in this database?

A junction table (also called a bridge or join table) creates a many-to-many relationship between two tables. The film_actors table stores pairs of film IDs and actor IDs, allowing each film to have multiple actors and each actor to appear in multiple films.

How do you verify that INSERT statements executed successfully in PostgreSQL?

After executing an INSERT statement, run a SELECT * FROM [table_name] query. If the query returns all expected rows without errors, the data insertion was successful and all records are now stored in the table.

Why use prepared SQL scripts instead of typing INSERT statements manually?

Prepared scripts ensure consistency, minimize typing errors, allow batch insertion of large datasets efficiently, and provide a repeatable, documented process that can be shared and version-controlled.