Junior — Middle
What are the main requirements for designing and using SQL databases that you know?
sobes.tech AI
Answer from AI
Main requirements for designing and using SQL databases:
- Data normalization — structuring tables to minimize redundancy and ensure integrity.
- Indexing — creating indexes to speed up searches and queries.
- Security — using parameterized queries to prevent SQL injection.
- Transactions — ensuring atomicity of operations to maintain data integrity.
- Backup and recovery — regularly creating backups.
- Query optimization — analyzing and improving query performance.
In Go, the database/sql package is usually used for working with SQL, along with drivers like pq for PostgreSQL. An example of a safe query:
stmt, err := db.Prepare("SELECT * FROM users WHERE email = ?")
if err != nil {
log.Fatal(err)
}
rows, err := stmt.Query(userEmail)
Parameters are passed separately here, which protects against injections.