Home > Articles > Data

  • Print
  • + Share This
Like this article? We recommend

Choosing a Coding Style

Coding styles are a matter of personal preference. Transact-SQL allows flexibility of spacing, formatting, and delimiting of code; hence the variety of styles that abound among people who code in this language. There is truly no difference between the two statements shown in Listings 1 and 2.

Listing 1 One style of coding.

SELECT
  Au_id,
  Au_lname,
  Au_fname
   FROM
     Authors
      WHERE
        State = 'ca'

Listing 2 A second style of coding.

select au_id, au_lname, au_fname from authors where state='ca'

These statements will return the same data and will take the same amount of time to execute. Some coders prefer the format in Listing 1 because in their opinion it's easier to read; others prefer to stick everything on one line as in Listing 2, avoiding changing case because it's easier to type.

I honestly don't think there's a single best approach to resolving this argument. Simply try agreeing on one standard and following it throughout the team as closely as you can.

  • + Share This
  • 🔖 Save To Your Account