Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active December 19, 2015 17:09
Show Gist options
  • Select an option

  • Save nicerobot/5989094 to your computer and use it in GitHub Desktop.

Select an option

Save nicerobot/5989094 to your computer and use it in GitHub Desktop.
SQL Formatting Standard

Good grief, please stop with this horrendous SQL formatting recommendation.

The interesting bits of SQL are not the keywords. Why in the world do you highlight them in BOLD?! The verbosity of them is ridiculously unwieldy.

The interesting bits of SQL is the structure of the statement. So highlight the structure!

These are my preferred styles:

create table humanresources.employee(
businessentityid int not null primary key,
empno int not null,
name text
);
insert into production.unitmeasure (name, unit_measure_code, modified_date) values
('FT2', 'Square Feet ', '20080923'),
('Y', 'Yards', '20080923'),
('Y3', 'Cubic Yards', '20080923')
;
select e.businessentityid, p.title, pp.phonenumber, pnt.name as phonenumbertype,
ea.emailaddress, a.addressline1, sp.name as stateprovincename,
cr.name as countryregionname
from humanresources.employee e
inner join person.person p
on p.businessentityid = e.businessentityid
inner join person.businessentityaddress bea
on bea.businessentityid = e.businessentityid
inner join person.address a
on a.addressid = bea.addressid
inner join person.stateprovince sp
on sp.stateprovinceid = a.stateprovinceid
inner join person.countryregion cr
on cr.countryregioncode = sp.countryregioncode
left outer join person.personphone pp
on pp.businessentityid = p.businessentityid
left outer join person.phonenumbertype pnt
on pp.phonenumbertypeid = pnt.phonenumbertypeid
left outer join person.emailaddress ea
on p.businessentityid = ea.businessentityid
where e.businessentityid = 12
and pp.phonenumber in ('123-456');
update humanresources.employee
set businessentityid = 12
where businessentityid = 13
and businessentityid != 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment