database_note_send
database_note_send
database_note_send
Data Integrity: Ensuring consistency, correctness and accuracy of data. Can be done
by:
Limitations are:
Database:
Relational database is a database in which the data items are linked by internal pointers.
Benefits of database approach:
Table is group of similar data, in a database, with rows for instance of entity and column
for attribute.
Record is a row in database table. Field is column. Each column of the table is an
attribute (description).
Primary key is unique identifier of a table. Foreign key is set of attributes in one table
that refer to the primary key in another table. Candidate key is an attribute or set of
attributes in a table where no tuple has the same value. Primary key is special case of
candidate key. Secondary key is alternative to primary key.
i.e., Candidate keys are unique set of attributes. We select one as primary key and rest
as secondary keys. For another table linked to this one, primary key of this table is the
foreign key.
Relationships
A relationship is link between two tables which is formed when one table in database
has a foreign key that refers to a primary key in another table in the database.
If primary key corresponding to foreign key isn’t there, this creates issue due to lack of
referential integrity.
Normalization process:
1NF: Ensuring that a table doesn’t contain repeating attributes or groups and all data in
the table are atomic. (Generally adding rows)
2NF: Ensuring that database is in 1NF + there are no partial dependencies on primary
key. (Generally adding tables)
3NF: 2NF + all fields are fully dependent on the primary key. (Adding tables)
Data definition Language (DDL): used to create, modify and remove data structures
that form a database.
Data Manipulation Language (DML): used to add, modify, delete and retrieve the data
stored in a relational database.
i.e., DDL defines structure or schema of the database and DML helps in managing and
manipulating data in the database.
DDL:
Creating a database:
Defining a table:
<column_name> datatype,
<column_name> datatype,
……
);
Example:
ADDRESS VARCHAR(50),
ClassID CHARACTER
);
Altering a table:
Example:
** After creating the table you can view the schema of table using .schema (sqlite)
** If you are using sqlite for practice: Use header on and mode column and width
value1, value2, … valueN to customize look of table
FROM table_name
WHERE [condition]
ORDER BY clause is used to sort the data in an ascending or descending order, based
on one or more columns.
SYNTAX:
SELECT column-list
FROM table_name
WHERE [condition]
GROUP BY clause is used to arrange identical data into groups. GROUP BY clause
precedes the ORDER BY clause.
SYNTAX:
SELECT column-list
FROM table_name
WHERE [conditions]
SYNTAX: