Assignment Set - 1 Database Management System (DBMS and Oracle 9i)
Assignment Set - 1 Database Management System (DBMS and Oracle 9i)
Assignment Set - 1 Database Management System (DBMS and Oracle 9i)
Advantages of a DBMS:-
This section describes the rules that can be applied to table columns to
enforce different types of data integrity.
Null Rule
A null is a rule defined on a single column that allows or disallows
inserts or updates of rows containing a null (the absence of a value) in
that column.
Attribute:-
• All the data relating to an entity is held in its attributes.
• An attribute is a property of an entity.
• Each attribute can have any value from its domain.
• Each entity within an entity type:
May have any number of attributes.
Can have different attribute values than that in any other entity.
Have the same number of attributes.
•Attributes can be
simple or composite
single-valued or multi-valued
• Attributes can be shown on ER models
• They appear inside ovals and are attached to their entity.
• Note that entity types can have a large number of attributes... If all are
shown then the diagrams would be confusing. Only show an attribute if
it adds information to the ER diagram, or clarifies a point.
8. Explain the following database operations with one query example for
each:
A) Insert:- insert statements have the following form:
INSERT INTO table (column1, [column2, ...]) VALUES (value1,
[value2, ...])
The number of columns and values must be the same. If a column is not
specified, the default value for the column is used. The values specified
(or implied) by the INSERT statement must satisfy all the applicable
constraints (such as primary keys, CHECK constraints, and NOT
NULL constraints). If a syntax error occurs or if any constraints are
violated, the new row is not added to the table and an error returned
instead.
Example:
INSERT INTO phone_book (name, number) VALUES ('John Doe',
'555-1212');
B) Delete: - The DELETE statement follows the syntax:
DELETE FROM table_name [ WHERE condition]
Any rows that match the WHERE condition will be removed from the
table. If the WHERE clause is omitted, all rows in the table are removed.
The DELETE statement does not return any rows; that is, it will not
generate a result set.
Executing a DELETE statement can cause triggers to run that can cause
deletes in other tables. For example, if two tables are linked by a foreign
key and rows in the referenced table are deleted, then it is common that
rows in the referencing table would also have to be deleted to maintain
referential integrity.
Delete rows from mytable using a subquery in the where condition:
DELETE FROM mytable WHERE id IN (SELECT id FROM
mytable2);
C) Update:-
An SQL UPDATE statement changes the data of one or more records in
a table. Either all the rows can be updated, or a subset may be chosen
using a condition.
The UPDATE statement has the following form:
UPDATE table_name SET column_name = value [, column_name =
value ...] [ WHERE condition]
For the UPDATE to be successful, the user must have data manipulation
privileges ( UPDATE privilege)on the table or column, the updated
value must not conflict with all the applicable constraints (such as
primary keys, unique indexes, CHECK constraints, and NOT NULL
constraints).
Set the value of column C1 in table T to 1, only in those rows where the
value of column C2 is "a".
UPDATE T SET C1 = 1 WHERE C2 = 'a';
Assignment Set – 2
Database Management System (DBMS and Oracle 9i)