When starting to build a website in multiple languages, we often wonder if we need to create a separate table for each language. The answer is a definitive NO.
Why use only one table?
Using a single table brings key advantages, which are shown below:
| Advantage | Description |
|---|---|
| Data Integrity | You only change the data in one place. |
| Easy Maintenance | The same SQL query works for all languages. |
Practical Example: The "customers" table
Below is the SQL code for creating a universal table:
CREATE TABLE IF NOT EXISTS stranke (
id INT AUTO_INCREMENT PRIMARY KEY,
ime VARCHAR(50) NOT NULL, -- First Name
priimek VARCHAR(50) NOT NULL, -- Last Name
ulica VARCHAR(100), -- Street
hisna_stevilka VARCHAR(10), -- House Number
posta VARCHAR(50), -- City/Post Office
postna_stevilka VARCHAR(10) -- Postal Code
);
In the PHP code, we then only change the table headers (e.g., "Ime" in Slovenian and "First Name" in English), while the data remains the same.