This episode is about the basic statements needed to create, read, update and delete data in a database system.
Let’s assume we work as a data scientist for Knight Industries. We want to help the Foundation of Law and Government to keep track of our operatives.
We decide to use a classic relational database management system or RDBMS. In order to explore Database Management Systems we can either install one locally or we can use an online tool like SQLFiddle.
To interact with RDBMS we use SQL – the Structured Query Language.
As the name says SQL (speak either S-Q-L or Sequel) is used to write structured queries. Think of “conversations” when You think of “queries”.
So, let’s fire up SQLFiddle. Continue reading “SQL-Basics: Create – Read – Update – Delete”
Sometimes your RDBMS does not allow You certain changes like updating a table without using a WHERE that uses a key column.
When You are really sure what You want to do:
SET SQL_SAFE_UPDATES = 0;
Sometimes You screw up your database design and you have redundancies i.e. your database is not normalized. If You want to correct that: Subqueries for the rescue! Continue reading “SQL-Basics – Subqueries: Update column with values from another column”
You can comment your queries with
-- This is a comment in SQL SELECT * FROM my_table -- WHERE id = 1