Static SQL
Static SQL refers to SQL statements that are embedded directly in application code and are pre-compiled or prepared at compile-time, rather than being constructed and executed dynamically at runtime. This approach involves hard-coded SQL queries where the structure is fixed and known in advance, often using placeholders for parameters. It contrasts with dynamic SQL, where queries are built as strings during program execution.
Developers should use Static SQL when performance and security are critical, as it allows for query optimization by the database at compile-time, reducing runtime overhead and preventing SQL injection attacks through parameterized queries. It is ideal for applications with predictable, repetitive database operations, such as reporting systems or transactional processing where query patterns are stable and known beforehand.