As-5 Data & Databases
As-5 Data & Databases
What is Data?
What is Information?
It is processed data which includes data that possess context, relevance, and
purpose. It also involves manipulation of raw data.
The term structured data refers to data that resides in a fixed field within a file or
record. Structured data is typically stored in a relational database (RDBMS). It can
consist of numbers and text, and sourcing can happen automatically or manually, as
long as it's within an RDBMS structure.
Unstructured data is more or less all the data that is not structured. Even though
unstructured data may have a native, internal structure, it's not structured in a
predefined way. There is no data model; the data is stored in its native format.
Structured Data
The database management system (DBMS) is the software that interacts with end
users, applications, and the database itself to capture and analyze the data.
The relational model was introduced by E.F. Codd in 1970 as a way to make database
management systems more independent of any particular application.
Tables
In a relational database, all data is held in tables, which are made up
of rows and columns.
Each table has one or more columns, and each column is assigned a
specific datatype, such as an integer number, a sequence of characters (for text), or
a date. Each row in the table has a value for each column.
2
Relational Integrity constraints is referred to conditions which must be present for a
valid relation.
Ex: 1
Primary key
The “id” column is what’s known as a primary key: a unique and non-null number
that refers to each record. Every record/row in a relational table has a primary key.
When designing a database, the key decisions are what data do you want to store
and what relationship exists between them. Right now we just have a customers
table, but let’s say we also want to store orders because we’re building an e-
commerce website.
This means we need a separate table for Orders. In order to associate a specific
order with a specific customer, we can use a foreign key relationship through
the customer_id field to link the two tables.
3
Ex: 2
Cardinality defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship set.
One-to-one − One entity from entity set A can be associated with at most one
entity of entity set B and vice versa.
One-to-many (or Many to One)− One entity from entity set A can be associated
with more than one entities of entity set B however an entity from entity set B,
can be associated with at most one entity.
Many-to-many − One entity from A can be associated with more than one entity
from B and vice versa.
4
Structured Query Language (SQL)
SQL lets you access and manipulate databases. Most of the actions you need to
perform on a database are done with SQL statements.
5
Data Definition Language (DDL)
To create a database:
To create a table:
CREATE TABLE Students (
StudID int,
LastName varchar(25),
FirstName varchar(20),
Address varchar(60),
Age int
);
DML is used for adding (inserting), deleting, and modifying (updating) data in
a database.
Inserting Data
6
Insert into Customer (1,”Saman”, 0112234556,” Negombo”,45);
Customer
Querying Data
CustomerName City
Saman Negombo
Nihal Chilaw
Silva Katana
Namal Negombo
CustomerName City
Nihal Chilaw
CustomerNo
1
2
4
CustomerNo City
3 Katana
4 Negombo
7
Link Tables
Joins and Unions can be used to combine data from one or more tables. The
difference lies in how the data is combined.
If two tables are joined together, then the data from the first table is shown in one set
of column alongside the second table’s column in the same row.
If two tables are “unioned” together, then the data from the first table is in one set of
rows, and the data from the second table in another set. The rows are in the same
result.
SELECT 23 AS StNo
UNION
SELECT 45 AS StNo;
StNo
23
45
SELECT * FROM
8
(SELECT 23 AS StNo) AS StNo1
JOIN
(SELECT 45 AS StNo) AS StNo2
ON (33=33);
StNo1 StNo2
23 45
Wildcard Characters
Represents zero or more bl% finds bl, black, blue, and blob
% characters
Represents any single h[oa]t finds hot and hat, but not hit
[] character within the brackets
Represents any character h[^oa]t finds hit, but not hot and hat
^ not in the brackets
9
Answer:
Answer:
10