Tumgik
quackbiology · 3 years
Text
Computer Programming: Day 1
SQL Basics
First we define what a database is. A database is a program that stores data and provides functionalities for adding, modifying, and requesting particular information (”querying”) from its stored data, and doing all of that really fast. It has many forms, but the most popular form is the Relational Database.
Tumblr media
(Source: https://www.omnisci.com/technical-glossary/relational-database)
Relational databases store each kind of data in a table. A table has a column for each data category and a row containing a set of data defined by the category.
Each table has a unique identifier (”primary key”), which identifies the information in the table, and each row contains a unique instance of data for the categories defined by the columns. This way, data can be accessed or reassembled in different ways without needing to reorganize the tables.
Most databases come with a Query language, like SQL. SQL is a programming language for accessing databases, and is the most popular one of them. 
The following are the basic things to do in SQL that I learned today:
Creating a table and inserting data
Say I want to create a table for a grocery list of 5 apples, 2 bottles of milk, and 3 bars of soap. This is how the code would look like:
CREATE TABLE groceries (id INTEGER PRIMARY KEY, item TEXT, quantity INTEGER, aisle INTEGER );
INSERT INTO groceries VALUES (1, “apple”, 5, 1);  INSERT INTO groceries VALUES (2, “milk”, 2, 2); INSERT INTO groceries VALUES (3, “soap”, 3, 6);
The CREATE TABLE command is followed by the table name “groceries” then its column names enclosed in parentheses. Each column is followed by the type of data it will store, namely INTERGER PRIMARY KEY for id, TEXT for item, and INTEGER for quantity.
The command INSERT INTO is followed by the table name. VALUES is followed by the data it will store under each column in the order that the columns are listed in the CREATE TABLE command. Take note that the SQL codes are all in uppercase letters and that each line of code is ended with a semi-colon.
Querying the table
Let’s add a column for “aisle” and add more items. I want to split grocery items between me and my friend. We can make a query first for items in aisles 1 to 3 and then aisles 4 to 6.
CREATE TABLE groceries (id INTEGER PRIMARY KEY, item TEXT, quantity INTEGER, aisle INTEGER );
INSERT INTO groceries VALUES (1, “apple”, 5, 1); INSERT INTO groceries VALUES (2, “milk”, 2, 2); INSERT INTO groceries VALUES (3, “soap”, 3, 6); INSERT INTO groceries VALUES
0 notes
quackbiology · 3 years
Text
Computer Science: Day 1
Intro to Algorithms
An algorithm is a set of instructions that a program follows to solve a problem.
An example of an algorithm is linear search or sequential search. It looks for an element in a list by trial-and-error– that is until a match is found or until all elements in a list has been searched.
Another example of an algorithm is the binary search or half-interval search or logarithmic search. Like linear search, binary search can be used to find an item in an arranged list (”array”) but it is more efficient as it uses characteristics from the array to eliminate wrong items. I wonder how this algorithm is represented mathematically. More on this later.
The route-finding algorithm is widely used in apps like Grab or Google Maps. This is used to solve path-finding problems like finding the shortest driving route from your location to the next, a path for exiting a maze, or how Queen Elizabeth II is related to Prince William III by finding the shortest connection in their family tree.
0 notes