40 likes | 216 Views
Where to do the programming?. Programming in the database language vs. Programming in the application language. Programming in the database language vs. the application language. Programming in the database language Stored procedures User-defined functions Triggers
E N D
Where to do the programming? Programming in the database language vs. Programming in the application language Where to do the programming?
Programming in the database language vs. the application language • Programming in the database language • Stored procedures • User-defined functions • Triggers • Programmed using a vendor-specific programming language • Microsoft T-SQL • Oracle PL/SQL • Etc. • Programming in the application language • C#, Java, etc making SQL calls directly • Called dynamic SQL Where to do the programming?
Programming abstraction • Databases must to be extensible • Adding new columns to existing tables • Adding new tables to existing databases • Changing the database means changing the application • If SQL is used in the application • Solution: The database should be encapsulated by an API • The API can be programmed in the database or in the application language • Database languages live as long as the database • Application languages has shorter lives • Source • Paul Nielsen: Why use Stored Procedures? Blog • http://sqlblog.com/blogs/paul_nielsen/archive/2009/05/09/why-use-stored-procedures.aspx Where to do the programming?
Technical reasons for programming in the database • Faster execution • Stored procedures etc. Are compiled once and executed many times • Less network traffic • With a single request/response the stored procedure can do a lot of work • Security • User can use the stored procedures without having any right on the base tables • Protection from SQL injection attacks • Stored procedures should check parameters • Source • Wikipedia: Stored procedure: Comparison with dynamic SQL • http://en.wikipedia.org/wiki/Stored_procedure#Comparison_with_dynamic_SQL Where to do the programming?