With today’s technology, we have so many ways to access information. We also have so many different tools on the Internat that we can access and participate with. That information is stored somewhere in an organized way. The storage of information or data is a database. It is controlled by DBMS — database management system and most of the database is structured with query language (SQL).
It’s a standard language for relationship databases, and what it does is to manage and keep in an organized way, different systems.
Language allows to create, update data, or retrieve relational data form databases. The fact is that you can manipulate data. SQL became very important in 1970 and still is today, where relational data is very important in data science. There are four types of databases: desktop data, text, relational (RDMS), NoSQL and object orientated. Today we will learn main concepts of the database.
1. Data Types in SQL.
Characters: CHAR(n) — fixed length string data and VARCHAR(n) — variable length string data.
Numbers: biting, int, smallint, tinyint, float, money.
Get Sabina S Ohlsen’s stories in your inbox
Join Medium for free to get updates from this writer.
Times and data: Data and Datatime.
2. Tables
Tables are main elements of database, they are objects that contain data in the database. A tuple in a table is also called a rows or record, and table is a set of tuples, like an unordered list.
3. Keys
Their role is to uniquely identify any row inside the table. It helps to identify relationship between different tables. Keys in SQL are sets of attributes that help to identify a row (tuple) and relationship(table). There are different types of keys.
- Super key — identifies rows in the table.
- Primary Key — is a column or group of columns in a table that uniquely identify every row in that table.
- Candidate Key — is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with no repeated attributes and can work as a Primary key.
- Alternate Key — set of one or more columns or group of columns in a table that uniquely identify every row in that database.
- Foreign Key — is a primary key in another table and creates a unique relationship between two tables. Helps to navigate between two different instances of an entity.
- Compound/Composite Key — has two or more attributes that allow you to uniquely recognize a specific record. It is possible that each column may not be unique by itself within the database.
- Surrogate Key — An artificial key which aims to uniquely identify each record is called a surrogate key. These kind of keys are unique because they are created when you don’t have any natural primary keys
4. Select Queries.
Selects and returns data stored in one table or more tables. Also, it selects from other queries. Helps to access data much faster.
5. Joins
So tables are structured with primary keys and linked with foreign keys and can be displayed with select queries. With join concept we can access and display data from multiple tables simultaneously by connecting them. We can then summarize and analyze for particular needs. To join two or more tables you can use id; we have different times of joins:
- inner — contains only data from tables that match.
- left outer — contains all data from the first referenced table and only retrieves data from the other table that matches.
- right outer — contains all data from the second referenced table and only gets data from the first table that matches.
- full outer — contains data from both tables that are opposite to each other and data is joined.
6. Data Modeling
With modeling data we can see the relationship between tables. Following relationships are:
- one-to-one — one data from one table is referenced to one data from other table.
- one-to-many — unique data from one table is related to the table that has multiple data values in the other table.
- many-to-many — there is no unique ID’s used in this relationship. Multiple rows in one table are related to multiple rows in the other table. An example would be when student that is enrolled in multiple classes and class has many students.
Personally, I find SQL a fascinating subject with so much more to offer. Considering how important data is nowadays, some may argue that is the most valuable commodity, diffrent form what we used to, oil, grain or coffee are something tangible that everyone can relate and understand. Data on the other hand not everyone can relate or has interest but it effects our day to day life more than ever even if we not aware of it, every-time we swipe a credit card or search the internet, we are giving away our interest to someone. It is fascinating but can also be scary at the same time.
Thank you for reading!









