Guidelines for good schema design

Comparing #7 with #8

Revision #8 was created by softark softark on Aug 14, 2018, 12:34:19 AM.

Fixed the link to the Chinese translation

Yii version

1.1

Tags

database, schema design

Content

[...]
Yii supports the notion of table prefix, which is useful in shared hosting environments where _all_ your applications share a single database. By prefixing your blog table names with `blog_`, your timekeeping application table names with `time_`, etc. they can all live in the same database without conflicting with each other.

The prefix `tbl_` is commonly seen in many tutorials and samples.

But the **classes** should never contain these prefixes, because you don't have the same need to avoid conflicts: your blog application is different from your timekeeping application.

```php

class TblComment extends CActiveRecord { // NO
class Comment extends CActiveRecord { // YES
[...]
By calling the FK `userid`, the BELONGS_TO relation of `$model->user` forms naturally and easily:

```php

class Post extends CActiveRecord {
[...]
If you have to look it up, it makes the code much more difficult to read and maintain.

Translations
 
------------
 
 
- Chinese version: [Yii良好的架构(schema)设计指南](https://www.yiiwiki.com/6blog.csdn.net/cd_0227/article/details/50536390 "中文翻译") - Russian version: [Руководство для проектирования хорошей схемы базы данных](http://phptime.ru/blog/yii/28.html) - Japanese version: [DB スキーマ設計のガイドライン](https://qiita.com/items/63e68a0172a1d2f92b5c)