The READS SQL DATA clause (often written together as READS SQL DATA or simply READS) is a routine characteristic defined in the SQL standard and implemented by several databases. When attached to CREATE PROCEDURE or CREATE FUNCTION, it signals that the routine is permitted to execute statements that read data (SELECT, read-only cursors) but is prohibited from executing data-modifying statements such as INSERT, UPDATE, DELETE, MERGE, TRUNCATE, or DDL. Marking a routine with READS SQL DATA lets the optimizer, security layer, and callers know that the routine is side-effect-free regarding modifications. Many engines treat READS SQL DATA routines as safe for use inside larger read-only transactions, in deterministic expressions, or in replication/parallel-execution contexts where write access is restricted. If the routine attempts to run a disallowed statement, the database raises an error at compile time (static checking) or run time (dynamic checking), depending on the engine. Other routine characteristics in the same family include NO SQL (no SQL statements at all), CONTAINS SQL (any SQL but no guarantee of read/write behavior), and MODIFIES SQL DATA (explicitly allows data changes). The SQL standard introduced these characteristics in SQL:1999, and implementations differ slightly in enforcement and naming. Always test your specific database behavior.
CONTAINS SQL, NO SQL, MODIFIES SQL DATA, deterministic functions, routine characteristics, stored procedures
SQL:1999 standard (feature T331, Routine Characteristics)
READS SQL DATA allows SELECT and other read-only operations but forbids data changes. NO SQL forbids all SQL statements, including SELECT.
Yes, but the database may treat the routine as potentially modifying data, which can restrict where it is callable. Declaring it explicitly clarifies intent and can improve optimization.
Alter or recreate the routine and replace the MODIFIES SQL DATA clause with READS SQL DATA. Ensure the body no longer contains write operations.
MySQL, MariaDB, and IBM Db2 perform compile-time checks. Some others accept the syntax but enforce it only at runtime or ignore it entirely.