Re: ID column naming convention

Поиск
Список
Период
Сортировка
От Jim Nasby
Тема Re: ID column naming convention
Дата
Msg-id 56204039.9080007@BlueTreble.com
обсуждение исходный текст
Ответ на Re: ID column naming convention  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
Ответы Re: ID column naming convention
Список pgsql-general
On 10/13/15 2:34 PM, Gavin Flower wrote:
>>
> My practice is to name the PRIMARY KEY as id, and foreign keys with the
> original table name plus the sufiix_id.
>
> By leaving the table name off the primary key name, and just using id,
> makes it more obvious that it is a primary key (plus it seems redundant
> to prefix the primary key name with its own table name!).

There's two things that are ugly about that though:

Joins become MUCH easier to screw up. When you have 5 different fields
that are all called 'id' it's trivial to mix them up. It's much harder
to accidentally do something like 'blah.person_id = foo.invoice_id'.

The other issue is common to all "bare word" names (id, name,
description, etc): it becomes completely impossible to find all
occurrences of something in code. If you grep your entire codebase for
'person_id', you know you'll find exactly what you want. Grepping for
'id' OTOH would be useless.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Jim Nasby
Дата:
Сообщение: Re: using postgresql for session
Следующее
От: Jim Nasby
Дата:
Сообщение: Re: problems with copy from file