Curriculum
Course: Data Analysis
Login
Text lesson

Introduction to SQL (Structured Query Language)

Creating Database and Table

•  Creating Database 

CREATE DATABASE (Name of the database)

Higlight and execute

  Creating Table 

CREATE TABLE (Name of the table) (

•Names   varchar (50),

•Age            int,  

•Gender      char(10),

•Phone        bigint,

•Emails       varchar (200),

•Address       varchar (50)

);

Highlight and execute
 

Difference between Integer and Big-integer

 

Integer  data type can store integers up to a certain size while
•Big-integer can store integers of any size.

Difference between Variable(var) and Variable-character(varchar)

•Variable (var) can only store a data of a specific length while
•Variable-character(varchar) can store data of any length.
 

Reasons for Integers and Big-integers not having specifications like other data types.

 The “INT” and “BIGINT” data types don’t have a length specification like the other data types. That’s because the length of the “INT” and “BIGINT” data types is determined by the specific SQL implementation you’re using. Different implementations of SQL have different maximum lengths for the “INT” and “BIGINT” data types.

SELECT Statement:

 

The SELECT statement retrieves data from one or more tables. You can select specific columns or use * to select all columns.

•Example

•SELECT *

• FROM table name;

How to modify data within a database using SQL.

There are three main operations: INSERT, UPDATE, and DELETE.

INSERT Statement:

•Adds new rows of data into a table.

INSERT INTO table name (column1, column2) VALUES (value1, value2);

•Example:

 

 

 

INSERT INTO  [student_information]

VALUES (

‘Mercy Olamiyi’,  28 ,’Female’,  08123456789 ,’[email protected]’  ,’No 80 Lagos street’

);

Highlight and execute

DELETE Statement:

 

Removes rows from a table based on a condition.
•DELETE FROM table name WHERE condition;
 
•Example:
 
DELETE FROM student_information WHERE Age = 28,
 
Highlight and execute
 
•Ensure caution when performing UPDATE and DELETE operations to avoid unintended consequences.
 
–ADDING MORE COLUMNS TO THE TABLE 
Example
 
ALTER TABLE [Student_information]
ADD state varchar(30)

 UPDATE Statement:

Modifies existing data in a table.

•UPDATE table name SET column1 = value1, column2 = value2 WHERE condition;

•Example:

 

UPDATE[ student_information] Set [State]=CaseWHEN Age = 28 THEN ‘Abia State’WHEN Age = 40 THEN ‘Edo State’Else NullEnd