As a\u00a0beginner\u00a0working in relational databases, there are some key concepts<\/a> and fundamentals to understand. These are the things I found most useful when getting started querying databases. Before you get going with writing\u00a0SQL queries<\/a> make sure you have a good grasp of theses basics.<\/p>\n\n\n\n
Data<\/strong> is organised in rows and columns stored in tables.<\/p>\n\n\n\n
Databases<\/strong> hold a collection of data stored in tables.<\/p>\n\n\n\n
one-to-one<\/strong>: one husband and one wife<\/p>\n\n\n\n
many-to-one<\/strong>: many students and one school<\/p>\n\n\n\n
one-to-many<\/strong>: one customer and many bank accounts<\/p>\n\n\n\n
many-to-many<\/strong>: many students and many teachers<\/p>\n\n\n\n
To make the most of the database we need to abide by rules to keep data clean, and organised. If we don’t we may as well be storing expensive\u00a0spreadsheets<\/a>,<\/p>\n\n\n\n
To help do this we can use a Primary Key<\/a>. This is a column that best identifies one unique row, and identifies each record as unique, like an ID.<\/p>\n\n\n\n
SQL is a standardised language for querying, manipulating and modifying relational databases<\/a>. The basic SQL statements used to transform the data into more segmented tables fall into four main groups.<\/p>\n\n\n\n
select name, address, city, country -- the columns to return \nfrom customers.address -- the schema and table to retrieve from \nwhere age = 21 and name = 'Bob Jones' -- filters for specific rows<\/code><\/pre>\n\n\n\n
Add new data with INSERT<\/h3>\n\n\n\n
insert into\ncustomers.address (name, address, city, country) -- where the data goes \nvalues ('Bob Jones', '123 Main St', 'Auckland', 'New Zealand'); <\/code><\/pre>\n\n\n\n
Remove data with DELETE<\/h3>\n\n\n\n
delete from\ncustomers.address --where the data is to be deleted from\nwhere name = 'Bob Jones' -- the condition that needs to be met<\/code><\/pre>\n\n\n\n
Modify data with UPDATE<\/h3>\n\n\n\n
update\ncustomers.address -- where the data is to be updated \nset country = 'New Zealand' -- the new value \nwhere city = 'Auckland'; -- the condition that needs to be met<\/code><\/pre>\n\n\n\n
\n\n\n\n
There are plenty of new concepts to get your head around with writing SQL and understanding the structure of a database. These are the relational database fundamentals I feel are important for complete beginners<\/a>.<\/p>\n\n\n\n
\n\n\n\nPhoto by Jeffrey Czum<\/a><\/strong> from Pexels<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"