Junior — Middle
How well do you know the language of database query composition?
sobes.tech AI
Answer from AI
The query language for databases is SQL (Structured Query Language). It is used for creating, reading, updating, and deleting data in relational databases.
Example of a simple data selection query:
SELECT id, name FROM users WHERE age > 18 ORDER BY name;
In Go, the database/sql package is typically used for working with databases, along with drivers for specific DBMSs. Queries are written in SQL, and the Go code is responsible for executing them and processing the results.
Example of executing a query in Go:
rows, err := db.Query("SELECT id, name FROM users WHERE age > ?", 18)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var id int
var name string
if err := rows.Scan(&id, &name); err != nil {
log.Fatal(err)
}
fmt.Println(id, name)
}