문제

In the application development there is a concept of defensive programming. How to implement defensive programming techniques and writing robust code using Transact-SQL?

도움이 되었습니까?

해결책

More generally

  • Understand TRY..CATCH and error handling
  • Datatype safety (no number compare against nvarchar for example)
  • Understand transactions
  • Consider stored procedures
  • Understand SQL injection

다른 팁

To add to what Scott said:

  • Use TRY / CATCH which is now supported in SQL Server
  • Validate the parameters of your procedures and use RAISERROR when things don't pass
  • Use transactions (carefully)
IF EXISTS()

is something that should be used a lot more often in T-SQL I think. A lot of times when developers write SQL code they don't think in terms of exceptions and faults as they do when writing regular code.

To consider the psychological angle to your question, you may find DBA Survival Skills – Think Defensively to be interesting reading.

In addition to what all the others said, enforce data integrity in the database!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top