DONT:
Plurals—use the more natural collective term where possible instead. For
example staff instead of employees or people instead of individuals.
I like naming my tables as plurals so that foreign keys to the table rows can have a name that relates to the table name. For instance, having column `Orders.employee` as an FK to an `Employees` record makes much more sense than having column `Orders.employee` as an FK to a `Staff` record.SQL style guide
11–20 of 151 posts
Re: SQL style guide
#12Though mostly good advice, I definitely disagree with this: DONT: Plurals—use the more natural collective term where possible instead. For example staff instead of employees or people instead of individuals. I like naming my tables as plurals so that foreign keys to the table rows can have a name that relates to the table name. For instance, having column `Orders.employee` as an FK to an `Employees` record makes much…
Which is better?
foreach (var employee in staff) {
}
or
foreach (var employee in employees) {
}
Re: SQL style guide
#13The suggestion to right-align the root keywords (e.g. SELECT, FROM, WHERE) and left-align everything else does make the SQL look good. But I can't think of a single editor that makes this type of alignment formatting easy to do. Can you?
Re: SQL style guide
#14> 1. The key should be unique to some degree.
If it's talking about primary keys (which it seems to be), it should be unique, full stop.
If it's not, where does uniqueness come in? Is it actually talking about indices, which, if I understand correctly, should have a wide spread of values (without any of them necessarily being unique) if they're to be useful?
Re: SQL style guide
#15I do it anyway to conform.
Re: SQL style guide
#16"Where possible avoid simply using id as the primary identifier for the table." Has anyone had trouble by using surrogate primary keys? I've found the opposite of what the author said could be more true: composite keys should be avoided instead.
Re: SQL style guide
#17"Where possible avoid simply using id as the primary identifier for the table." Has anyone had trouble by using surrogate primary keys? I've found the opposite of what the author said could be more true: composite keys should be avoided instead.
But that's just playing devil's advocate. In general I think ids are fine because ORMs play nice with them and FKs are simple.
Re: SQL style guide
#18"Where possible avoid simply using id as the primary identifier for the table." Has anyone had trouble by using surrogate primary keys? I've found the opposite of what the author said could be more true: composite keys should be avoided instead.
Re: SQL style guide
#19An interesting read! I do follow certain rules when writing SQL, and I agree that having them and following them is a good idea. Plenty of what is in the article looks like good advice. However, these rules do not always appear to be consistent with how the code in (most) other programming languages is written. Consider indentation, for example. The usual approach is to line up those elements of the code which corres…
Here's your huckleberry:
SELECT
fs.id,
fs.file_hash
FROM
file_system fs,
other_table ot
WHERE
file_name = '.vimrc' AND
fs.id = ot.file_system_idRe: SQL style guide
#20Though mostly good advice, I definitely disagree with this: DONT: Plurals—use the more natural collective term where possible instead. For example staff instead of employees or people instead of individuals. I like naming my tables as plurals so that foreign keys to the table rows can have a name that relates to the table name. For instance, having column `Orders.employee` as an FK to an `Employees` record makes much…
Not to mention with an ORM tool you'll have an Employee object, and probably call your collection employees. Which is better? foreach (var employee in staff) { } or foreach (var employee in employees) { }
Really ? IMHO this is a bad practice : it makes the code les readable and breaks the auto-completion ...