DBMS Part 2
DBMS Part 2
Columns or Fields
A column is a set of data values of a particular simple type
Rows or Records or Tuples
A row also called a record or tuple represents a single, data item in a table.
A database table can be visualized as consisting of rows and columns or fields. Each row
in a table represents a set of related data, and every row in the table has the same
structure.
Numeric Types - Used for describing numeric values for the field
Alphanumeric datatype
Date and
Time - used for describing date and time values for the field
PRIMARY KEY
The PRIMARY KEY uniquely identifies a record in a table.
Primary keys must contain
● UNIQUE values
● cannot contain NULL values
■ A table can have only ONE primary key; and in the table
■ primary key can consist of single or multiple columns (fields).
■ multiple columns (fields) are used they are called a composite key
Delete Primary Key
You can clear the primary key constraints from the table with the syntax given below.
FOREIGN KEY
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY
KEY in another table.
The table containing the foreign key is called the child table, and the table containing the
candidate key is called the referenced or parent table.
Example:
"Persons" table:
PersonI LastNam FirstNam
Age
D e e
1 Hansen Ola 30
2 Svendson Tove 23
3 Pettersen Kari 20
"Orders" table:
OrderNumbe PersonI
OrderID
r D
1 77895 3
2 44678 3
3 22456 2
4 24562 1
Notice that the "PersonID" column in the "Orders" table points to the "PersonID" column
in the "Persons" table.
The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables.
The FOREIGN KEY constraint also prevents invalid data from being inserted into the
foreign key column, because it has to be one of the values contained in the table it points
to.
MANIPULATING DATA
◆ Data Definition Language (DDL)
◆ Data Manipulation Language (DML)
Syntax
Syntax
Syntax
The basic syntax of an ALTER TABLE command to add a New Column in an existing table
is as follows.
The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is
as follows.
Syntax
You can specify a condition using the comparison or logical operators like >, <, =,LIKE,
NOT, etc.
Example:
SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000;
● use the WHERE clause with a DELETE query to delete the selected rows, otherwise
all the records would be deleted.
+----+----------+-----+-----------+----------+