You are on page 1of 5

INTRODUCTION TO PROGRAMMING

High-level language: High-level languages are programming languages that are designed to be easily
understood by humans. They are closer to natural language

Low-level language: Low-level languages are programming languages that are closer to the machine
code and hardware architecture.

Compiler: A compiler is a program that translates the entire source code of a high-level programming
language into machine code or an intermediate code in a single compilation process.

Interpreter: An interpreter is a program that reads and executes the source code of a high-level
programming language line by line.

Database: A database is a structured collection of data that is organized and stored in a way that makes it
easy to manage, retrieve, and update.

RDBMS: A Relational Database Management System (RDBMS) is a software system that manages and
organizes data in a relational database. It is based on the principles of the relational model

SQL: Structured Query Language, is a domain-specific programming language designed for managing
and manipulating relational databases. SQL provides a standardized way to interact with relational
database management systems (RDBMS)

SQL Commands:

1. Data Query Language (DQL):

· SELECT: Retrieves data from one or more tables.

Syntax:

SELECT column1, column2 FROM table WHERE condition;


2. Data Definition Language (DDL):

· CREATE TABLE: Creates a new table.

Syntax:

CREATE TABLE table_name (

column1 datatype,

column2 datatype,

...

);

· ALTER TABLE: Modifies the structure of an existing table.

Syntax:

ALTER TABLE table_name ADD column_name datatype;

· DROP TABLE: Removes a table and its data from the database.

Syntax:

DROP TABLE table_name;

· TRUNCATE : used to quickly and efficiently remove all rows from a table

Syntax:

TRUNCATE TABLE table_name;

3. Data Manipulation Language (DML):

· INSERT INTO: Adds new records to a table.

Syntax:

INSERT INTO table_name (column1, column2) VALUES (value1, value2);

· UPDATE: Modifies existing records in a table.

Syntax:

UPDATE table_name SET column1 = value1 WHERE condition;

· DELETE FROM: Removes records from a table.


Syntax:

DELETE FROM table_name WHERE condition;

Order By: The ORDER BY clause in SQL is used to sort the result set of a query based on one or more
columns. It is particularly useful when you want to retrieve data in a specific order, such as ascending or
descending order, and is commonly used in conjunction with the SELECT statement.

The basic syntax of the ORDER BY clause is as follows:

For Ascending

SELECT column1, column2, ...

FROM table

ORDER BY column ASC;

For Descending

SELECT column1, column2, ...

FROM table

ORDER BY column DESC;

Primary Key : A primary key is a column or set of columns in a table that uniquely identifies each record
in that table. It must contain unique values, and no NULL values are allowed. A table can have only one
primary key

Foreign Key: A foreign key is a column or set of columns in a table that refers to the primary key of
another table. It establishes a link between the two tables, creating a relationship.

NOT NULL Constraint: The NOT NULL constraint ensures that a column cannot have NULL values. It
requires each row to have a value for that column.

Unique Constraint:The UNIQUE constraint ensures that all values in a column (or a set of columns) are
unique. It allows NULL values
Default Constraint: The DEFAULT constraint allows you to specify a default value for a column. If no
value is provided during an insertion, the default value is used

Joins

In SQL, a join is used to combine rows from two or more tables based on a related column between them.
Joins are fundamental for querying data from multiple tables in a relational database. There are several
types of joins, each serving a different purpose. Here are the common types of joins along with their
syntax:

1. INNER JOIN: Returns only the rows where there is a match in both tables based on the specified
condition.

Syntax:

SELECT columns

FROM table1

INNER JOIN table2 ON table1.column = table2.column;

2. LEFT JOIN: Returns all rows from the left table (table1) and the matched rows from the right table
(table2). If there is no match, NULL values are returned for columns from the right table.

Syntax:

SELECT columns

FROM table1

LEFT JOIN table2 ON table1.column = table2.column;

3. RIGHT JOIN: Returns all rows from the right table (table2) and the matched rows from the left table
(table1). If there is no match, NULL values are returned for columns from the left table.

Syntax:

SELECT columns

FROM table1
RIGHT JOIN table2 ON table1.column = table2.column;

4. FULL JOIN: Returns all rows when there is a match in either the left or right table. If there is no
match, NULL values are returned for columns from the table without a match.

Syntax:

SELECT columns

FROM table1

FULL JOIN table2 ON table1.column = table2.column;

You might also like