SQL Lec 01 03
SQL Lec 01 03
Lecture 2-3
Md. Abdul Basit
18 Sept 2023
Introduction to Databases
Finding a person’s telephone number can be time consuming, especially if the telephone book contains a large
number of entries (slow data retrieval rate).
A telephone book is indexed only by last/first names, so finding the names of the people living at a particular
address, while possible in theory, is not a practical use for this database (limited indexing capabilities).
From the moment the telephone book is printed, the information becomes less and less accurate as people
move into or out of a region, change their telephone numbers, or move to another location within the same
region (outdated information).
Because of the cumbersome nature of paper databases, some of the first computer applications developed were
database systems, which are computerized data storage and retrieval mechanisms.
Because a database system stores data electronically rather than on paper, a database system is able to retrieve
data more quickly, index data in multiple ways, and deliver up-to-the-minute information to its user community.
Early database systems managed data stored on magnetic tapes. While these database systems were a significant
improvement over paper databases, they are a far cry from what is possible with today’s technology.
Modern database systems can manage petabytes of data, accessed by clusters of servers each caching tens of
gigabytes of that data in high-speed memory.
Often, the tables in a relational database have shared information between them, causing a relationship to form
between tables. This is where a relational database gets its name from.
In a relational database, a table uses columns to define the information being stored and rows for the actual data.
Each table will have a column that must have unique values—known as the primary key. This column can then be
used in other tables, if relationships are to be defined between them. When one table’s primary key is used in
another table, this column in the second table is known as the foreign key.
Historically, the most popular relational databases have been Microsoft SQL Server, Oracle Database, MySQL and IBM
DB2. Several free versions of these RDBMS platforms have gained popularity over the years, such as PostgreSQL,
SQLite, MariaDB, etc.
Instead, the non-relational database uses a storage model optimized for specific requirements of the type of data
being stored.
Some of the more popular NoSQL databases are MongoDB, Apache Cassandra, Redis, Apache HBase, etc.
Along with Codd’s definition of the relational model in 1970, he proposed a language called DSL/Alpha for
manipulating the data in relational tables.
Shortly after Codd’s paper was released, IBM commissioned a group to build a prototype based on Codd’s ideas.
This group created a simplified version of DSL/Alpha that they called SQUARE. Refinements to SQUARE led to a
language called SEQUEL, which was, finally, shortened to SQL.
While SQL began as a language used to manipulate data in relational databases, it has evolved to be a language for
manipulating data across various database technologies.
SQL goes hand in hand with the relational model because the result of an SQL query is a table (also called, in this
context, a result set). Thus, a new permanent table can be created in a relational database simply by storing the
result set of a query.
Similarly, a query can use both permanent tables and the result sets from other queries as inputs (to be explored
later in this course).
SQL schema Statements: used to define the data structures stored in the database
SQL data Statements: used to manipulate the data structures previously defined using SQL schema
statements
For example, to create a new table in your database, you would use the SQL schema statement create table,
whereas the process of populating your new table with data would require the SQL data statement insert.
This statement creates a table with two columns, corp_id and name, with the corp_id column identified as the
primary key for the table.
This statement adds a row to the corporation table with a value of 27 for the corp_id column and a value of
'Acme Paper Corporation' for the name column.
SELECT
name, id
FROM
testdb.corporation;