16
8th of October 2014 Zen SQL Best practices to query and database design by Clément Prévost

Steam Learn: Zen SQL

  • Upload
    inovia

  • View
    30

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Steam Learn: Zen SQL

8th of October 2014

Zen SQLBest practices to query and database design

by Clément Prévost

Page 2: Steam Learn: Zen SQL

8th of October 2014

The Zen way to SQL

● State of the art

● Readability best practices:a. Database schemab. Query

Page 3: Steam Learn: Zen SQL

8th of October 2014

State of the art

● ORM (Doctrine, ActiveRecord, ...)○ Hides the database schema and queries, follow your

applicative coding best practices

● Query Builder (Zend\Db\Sql, …)○ Hides the queries, not the schema

● Raw (Migration scripts, performance critical task, Analytics)○ DIY

Page 4: Steam Learn: Zen SQL

8th of October 2014

The Zen way to SQL

● State of the art

● Readability best practices:a. Database schemab. Query

Page 5: Steam Learn: Zen SQL

8th of October 2014

a) Database schema best practices

A. KISS ○ Beware of overengineering○ Don’t let optimizations get in the way of simplicity

B. Explicitness is the key○ Ban abbreviations, “status” column and add

comments

C. Your business WILL evolve, same with your schema○ Never be afraid to refactor, rename and move stuff

around

Page 6: Steam Learn: Zen SQL

8th of October 2014

Case study: Database schema BP

Page 7: Steam Learn: Zen SQL

8th of October 2014

1

3

2

1

2

3

3

Page 8: Steam Learn: Zen SQL

8th of October 2014

The Zen way to SQL

● State of the art

● Readability best practices:a. Database schemab. Query

Page 9: Steam Learn: Zen SQL

8th of October 2014

b) Query best practices

A. Comments and documentation, Avoid deep nesting, Reuse external libraries

B. Know your enemy: Long vs. complex queries

C. Tools: IDE, Database specificity, SQL capabilities

Page 10: Steam Learn: Zen SQL

8th of October 2014

Page 11: Steam Learn: Zen SQL

8th of October 2014

Page 12: Steam Learn: Zen SQL

8th of October 2014

Page 13: Steam Learn: Zen SQL

8th of October 2014

Key things to remember

● Work it step by step○ Have a perfect schema, then work on beautiful

queries

● Know your tools, learn advanced SQL

● You already know how○ Good coding practices also apply to SQL (queries

AND schema)

Page 14: Steam Learn: Zen SQL

8th of October 2014

Questions ?For online questions, please leave a comment on the article.

Page 15: Steam Learn: Zen SQL

8th of October 2014

Join the community !(in Paris)

Social networks :● Follow us on Twitter : https://twitter.com/steamlearn● Like us on Facebook : https://www.facebook.com/steamlearn

SteamLearn is an Inovia initiative : inovia.fr

You wish to be in the audience ? Contact us at [email protected]