Introduction to SQl

Next Story

How to create a toast in Android Kotlin

SQL is a general programming language that is used to control database tables. It is common to store data in databases in sql format.

We will be focusing on postgres in this article.

Sql commands are very useful to select and analyze data in our databases.

To start the example, lets create a database called examples.

CREATE DATABASE examples;

Next, lets create a table named objects.

CREATE TABLE objects (
  id bigserial,
  name varchar(50),
  date date,
  age numeric
);

In this above code, an objects table is created with the fields: id, first_name, name, date, and age.

Id is of type bigserial which increments the count each time a new record is stored in the objects table.

Name is a varchar datatype of max 50 character length.

Date is of date type and age is a number type.

Next, lets add a few records into our objects table.

INSERT INTO objects (name, date, age)
VALUES ('Jay', '2020-10-11', 33),
('Erik', '2019-11-10', 27);

In the above code, we added 2 records to our objects database with data that matched each field and data type.

Next, let’s try to query our database for some of the records with the SELECT statement.

SELECT * from objects;

SELECT * will return all the columns from the table. If we would like to return only certain columns from the table then we could just state those columns.

SELECT name, date FROM objects;

Leave a Reply

Your email address will not be published. Required fields are marked *

https://www.googletagmanager.com/gtag/js?id=UA-63695651-4