Backpack Tools4 Sql Dev

29
XII Encontro da comunidade SQLPort

description

A brief of some SQL base advices in order to keep your DB more accurate, optimized and safe.

Transcript of Backpack Tools4 Sql Dev

Page 1: Backpack Tools4 Sql Dev

XII Encontro da comunidade SQLPort

Page 2: Backpack Tools4 Sql Dev

Name: Gonçalo Chaves Alias: Chaves Job: Senior Analyst Company: Viatecla Im: [email protected] Tw: @gchaves Hobbies: reading, photo, gaming Email: [email protected] Communities: xamlpt, pontonetpt, sqlport

Page 3: Backpack Tools4 Sql Dev

“The biggest problem in databases is the base data…”

Page 4: Backpack Tools4 Sql Dev

Main challenges Why we don’t care Analysis and procedures Tools Use Cases References

Page 5: Backpack Tools4 Sql Dev

Engineers knows programing but they don’t know SQL!

Page 6: Backpack Tools4 Sql Dev

Rookies don’t thing in scalability!

Page 7: Backpack Tools4 Sql Dev

High availability Scale and Scale Trustful transactions Performance and tuning Maintenance and archiving Partitioning Data integrity

Page 8: Backpack Tools4 Sql Dev

The easy path Comfort, learning is a painful process No professional training No time! The big truck rule Scale and trust aren’t known “Microsoft’s lema”

Page 9: Backpack Tools4 Sql Dev

Don’t know the engine Wrong Assumptions Re-use views, queries, with no limits Data type? What? nvarchar don’t fit in all? Unknown Transaction Isolation levels Tons of locks on a single query

Page 10: Backpack Tools4 Sql Dev

Normalization

Careful to much can be inefficient

Appropriate Keys and Indexes Right Primary and FK’s

Choose for relations and integrity

Page 11: Backpack Tools4 Sql Dev

Don’t over on Indexes

Take’s disk space

Drop index for bulk insertion

Some WHERE’s clauses can’t take advantage on ix

Evaluate and test you ix

Page 12: Backpack Tools4 Sql Dev

Each Database is a Database

BETWEEN can be more efficient than operators

Native functions (Convert, format…)

Aggregate functions (max, min, count, …)

Page 13: Backpack Tools4 Sql Dev

The NULL cancer… you must know NULL well

ISNull can be a painful

Wrong assumption on fields

Null datatype vs “Null”

Non safe transaction

Logic looseness

Page 14: Backpack Tools4 Sql Dev

My debug:

Profiler… yeah it’s heavy but it’s useful!

TA – tuning advisor

Activity monitor

Look for index, keys, fragments,

Page 15: Backpack Tools4 Sql Dev

Daily, every sql dev is also an sql admin!

RedGate suite

QueryExpress (light, keep simple)

TableDiff.exe

DMVStats (dataware house)

SQL Server Cache manager

Page 16: Backpack Tools4 Sql Dev

DBA? Where?

SQL Internals Viewer

SQLQueryStress (in dev or stage scenarios)

SQLIO Disk Benchmark tool (on server)

Page 17: Backpack Tools4 Sql Dev

SQL Security

Roles may be insufficient

Prevent SQL injection

Prevent non logic queries that can burn your data

Remember, it’s more easier broke sql security by your app than anything else.

Page 18: Backpack Tools4 Sql Dev

The devil ….

SELECT *

Page 19: Backpack Tools4 Sql Dev

Dam accelerators …. ADO.NET

SQLDATASOURCE

LINQ to SQL

Entity Framework …

Page 20: Backpack Tools4 Sql Dev

Abuses on Group by ; Having; Inner join

Sub queries with sub queries with …

#temp_table for everything…

DML cmd’s

Constraints for everything…

Page 21: Backpack Tools4 Sql Dev

Good sense

Know your data

Maintenance

Job your data Integrity vs Performance

The balance is the key

0

1

2

3

4

5

Jan Fev Mar April May June

Frag

Perf

Disk

Page 22: Backpack Tools4 Sql Dev

Database – xpto 1500 tables

2700 stored procedures

~1.5 M transaction per day Delete in cascade … Broke process

Restart server

Page 23: Backpack Tools4 Sql Dev

Normalize has needed Test your database Schedule jobs Create Index’s where needed Use right tools

full text search, TA, SSIS

Page 24: Backpack Tools4 Sql Dev

Avoid triggers Partitioning Archive data Data type right usage Think in your transaction mode Use safe locks Test, application stress and faulty

Page 25: Backpack Tools4 Sql Dev

Document you DB Keep scripts in safe Update your scripts Use facts not assumptions Cross your test with others Right lock safe usage Define db architecture

Page 26: Backpack Tools4 Sql Dev

A good DB start’s on your apps Cache is more than welcome “The 4 connections challenge..” Multiple Environments keep DB’s updated Keep your analysis update

Page 27: Backpack Tools4 Sql Dev

Developers exists in C# not in SQL – Deal with it!

Train your team – code review; sessions; books

Use the right tools on right scenarios

Integrity vs Performance

Keep in mind security concerns

Make Maintenance plans – from the beginning

Page 28: Backpack Tools4 Sql Dev

Usual blog’s / Communities SQL 2008 internals Write Smart Sql SQL For Smarties Sql forums … sqlport

Page 29: Backpack Tools4 Sql Dev

Thank you all Do right SQL before the pain! Follow me at:

http://pontonetpt.org/blogs/chaves http://xamlpt.com/blogs/chaves

[email protected] www.viatecla.com