Relational databases are valuable integration tools when the boundary between control and information is designed clearly.
SQL databases are widely used around industrial systems for event storage, production reporting, configuration, batch context and MES integration. Their value is transactional consistency, query capability and a well-understood model for structured records. They should not be treated as a generic replacement for the deterministic control logic that belongs in a PLC or dedicated control platform.
Good fits for SQL
- Persisting alarm and event records with traceable identifiers.
- Staging production messages before they are forwarded to another system.
- Joining equipment events with order, batch or material context.
- Reporting counts, cycle times, downtime categories and quality outcomes.
- Maintaining controlled configuration and audit data under appropriate governance.
Be careful with synchronous dependencies
A PLC sequence that must execute predictably should not wait indefinitely for a database query. Database locks, storage delays, network interruptions and maintenance operations are normal failure modes. If a database is temporarily unavailable, decide whether the control process continues, whether data are buffered, how long the buffer can hold, and how operators are notified. The policy should be written before the incident.
Design the schema around events
For a durable event record, consider an immutable event ID, source system, equipment identity, event type, source timestamp, ingestion timestamp, quality/validation status and a version or sequence field. A unique constraint on the event ID can enforce duplicate protection. Store units and semantics explicitly rather than naming a column Value2 and relying on institutional memory.
Use transactions for a coherent write, parameterised SQL to prevent injection, least-privilege accounts and connection pooling where appropriate. Avoid granting an application broad administrative rights simply because a permission error appeared during commissioning. The error may indicate a missing, narrowly scoped permission rather than a need for db_owner.
Retries and exactly-once expectations
A client retry after a timeout can produce a duplicate if the server committed the first request but the acknowledgement was lost. Therefore, “retry on error” is incomplete unless the write is idempotent. Use stable identifiers and a receiver-side uniqueness rule; record the original request outcome and reconcile uncertain transactions. Exactly-once delivery across independent systems is not something to assume from a TCP connection or a stored procedure name.
Operational checks
Monitor queue length, oldest unprocessed event age, transaction failures, deadlocks, disk capacity, backup success and replication health where applicable. Test restoring a backup, not just creating one. Keep development, test and production environments distinct and version database changes along with application changes.
The central design question is not “Can the PLC write to SQL?” It is “What happens to the process and the data when SQL is slow, unavailable, restored from backup or receiving the same event twice?” Answer that question and the database usually finds its proper place in the architecture.