Library Carpentry: SQL
- SQL is a powerful language used to interrogate and manipulate
relational databases.
- People working in library- and information-related roles have skills
that allow them to use SQL to organize and access data.
- SQL is ideal for querying databases
- SQL queries have a basic query structure starting with
SELECT
field FROM table with additional keywords and
criteria that can be used.
- Use
WHERE
to filter and retrieve data based on specific
conditions.
- Use
AND, OR, and NOT
to add additional conditions.
- Use the comparison keyword
LIKE
and wildcard characters
such as %
to match patterns.
- SQL can be used for reporting purposes.
- Queries can do arithmetic operations on field values.
- Joining two tables in SQL is an good way to analyse datasets,
especially when both datasets provide partial answers to questions you
want to ask.
- Creating aliases allows us to spend less time typing, and more time
querying!
- Saving queries as ‘Views’ allows you to save time and avoid
repeating the same operation more than once.
- Database design is helpful for creating more efficient
databases.
- Use CREATE and DROP to create and delete tables.
- Use INSERT to add data.
- Use UPDATE to modify existing data.
- Use DELETE to remove data.
- It is simpler and safer to modify data when every record has a
unique primary key.
- Do not create dangling references by deleting records that other
records refer to.
- There are many ways to write an SQL queries, but some look better
than others.