SQL EASILY EXPLAINED
SQL EASILY EXPLAINED
Many if not
all organizations have large amounts of data that need to be securely stored,
updated and retrieved easily. Nowadays data is more valuable than oil if analyzed
and interpreted properly.
Then what
is data? in simple terms data are raw facts, example comments on a Facebook
post.
In the Facebook
comment example the Facebook company
must have a database that stores those comments. This brings us to the term
database.
A database
is easily defined as a container (think of a box) that stores data. A database
can be relational and no relational. Relational database is the oldest form of
a database as it was the first and
currently most commonly used.
Storing
data in files can lead to redundancy, wastage of time and there is a
possibility of having a hard time trying to retrieve files especially when
looking for related information. Here is when DBMS come to our aid. What is DBMS?
it is an acronym of database management system. DBMS is a generalized software
that is used to manage databases. The software applications can be python, c++,JavaScript
and even R.
SQL ,structured
query language as the name suggests is used to query the databases is the
standard of querying the database. Most
programmers use the standard in order to allow other people to read the queries
easily and also allow for understanding when
updating.
The queries
are usually written in capital letters and when ending a code, we use a semicolon
.SQL is not case sensitive but we must maintain the heywell standards. Some SQL
flavors are mysql,oracle,posgresql,Microsoftsql
server etc. the mentioned above are relational. The most common no relational
database is mongo dB.
The major aims
of querying a database is CRUD
C- create
R-read
U- update
D-delete.
Here I will
give you some simple MySQL queries and some of the mostly used aggregate functions.
Let’s say
provided the dataset below create a database called college?
Students table:
Students ID |
Name |
Age |
Year of admission |
1 |
Onunga |
78 |
2017 |
2 |
Wanga |
23 |
2016 |
3 |
Ogeto |
39 |
2015 |
4 |
Malenya |
56 |
2017 |
Course table:
Course ID |
Course name |
Students ID |
Department |
1 |
arts |
4 |
Education |
2 |
physics |
3 |
Science |
3 |
statistics |
1 |
Mathematics |
4 |
economics |
2 |
Bussiness |
CREATING
A DATABASE
we use create query to create a database ie
CREATE DATABASE college;
Now that we have created the database college lets create the tables and insert the provided data
CREATE TABLE studentS (
id INT,
name VARCHAR(50),
year_adm INT,
age INT
);
CREATE TABLE Course(
course_id INT,
student_id INT,
department VARCHAR(200 )
) ;
Students id
is an integer field ,students name is a character field and the set limit for
cgaractors in this field is 50.
INSERTING
THE DATA INTO THE TABLES
Here we shall use the query insert into
INSERT
INTO studentS(id,s_name,year_adm,age)
VALUES(1,'onunga',2017,78);
INSERT
INTO studentS(id,s_name,year_adm,age)
VALUES(2,'wanga',2016,23);
INSERT
INTO studentS(id,s_name,year_adm,age)
VALUES(3,'ogeto',2015,39);
INSERT
INTO studentS(id,s_name,year_adm,age)
VALUES(4,'malenya',2017,56);
INSERT
INTO Course
(course_id,student_id,department)
VALUES(1,4,'Education');
INSERT
INTO Course
(course_id,student_id,department)
VALUES(2,3,'Science');
INSERT
INTO Course
(course_id,student_id,department)
VALUES(3,1,'Mathematics');
INSERT
INTO Course
(course_id,student_id,department)
VALUES(4,2,'Bussiness');
Comments
Post a Comment