30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1: Writing Readable <strong>SQL</strong><br />

Pluralizing<br />

A pluralizer will always name a table after a quantity of entities rather than an entity. The<br />

Customer table will be called Customers, and Invoice will be Invoices. Ideally, the<br />

use of a collective name for the entities within a table is best, but failing that, the singular<br />

noun is considered better than the plural.<br />

Abbreviating (or abrvtng)<br />

An abbreviator will try to make all names as short as possible, in the mistaken belief that<br />

the code will run faster, take less space, or be, in some mystical sense, more efficient.<br />

Heaving out the vowels (the "vowel movement") is a start, so that Subscription<br />

becomes Sbscrptn, but the urge towards the mad extreme will lead to Sn. I've heard<br />

this being called "Custing," after the habit of using the term Cust instead of Customer. To<br />

them, I dedicate Listing 1-1.<br />

CREATE TABLE ## ( # INT )<br />

DECLARE @ INT<br />

SET @ = 8<br />

INSERT INTO ##<br />

( # )<br />

SELECT @ % 2<br />

SELECT *<br />

FROM ##<br />

Listing 1-1: Abrvtng mdnss.<br />

This habit came from the old Fortran days when you could only use six characters at the<br />

most. <strong>SQL</strong> 92 allows 18 characters, but <strong>SQL</strong> <strong>Server</strong> has no practical limit, though you<br />

must keep it under 128 characters.<br />

20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!