Modify Primary Key of Countrylanguage Table

Beginner

In this project, you will learn how to modify the primary key of the `countrylanguage` table in a MySQL database. The initial primary key was based solely on the `CountryCode` column, but for better organization, you will create a composite primary key using both the `CountryCode` and `Language` columns.

SQLMySQL

Introduction

In this project, you will learn how to modify the primary key of the countrylanguage table in a MySQL database. The initial primary key was based solely on the CountryCode column, but for better organization, you will create a composite primary key using both the CountryCode and Language columns.

👀 Preview

MariaDB [world]> DESC countrylanguage;
+-------------+---------------+------+-----+---------+-------+
| Field       | Type          | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| CountryCode | char(3)       | NO   | PRI |         |       |
| Language    | char(30)      | NO   | PRI |         |       |
| IsOfficial  | enum('T','F') | NO   |     | F       |       |
| Percentage  | decimal(4,1)  | NO   |     | 0.0     |       |
+-------------+---------------+------+-----+---------+-------+
4 rows in set (0.001 sec)

🎯 Tasks

In this project, you will learn:

  • How to access MySQL using the sudo command without a password
  • How to import data from an SQL file into a MySQL database
  • How to modify the primary key of a table to a composite key

🏆 Achievements

After completing this project, you will be able to:

  • Understand the importance of using a composite primary key for better data organization
  • Confidently make changes to the primary key structure of a MySQL table
  • Apply your knowledge of SQL statements to achieve desired database modifications

Teacher

labby

Labby

Labby is the LabEx teacher.