dbms (1)
dbms (1)
A Transaction is a set of SQL statements that are executed on the data stored in
DBMS. Whenever any transaction is made these transactions are temporarily happen
in database. So, to make the changes permanent, we use DCL commands.
COMMIT
ROLLBACK
SAVEPOINT
COMMIT:
Syntax: commit;
2. ROLLBACK:
This command is used to get the data or restore the data to the last save-point or last
committed state. If due to some reasons the data inserted, deleted or updated is not
correct, you can rollback the data to a particular save-point or if save-point is not done,
then to the last committed state.
Syntax: rollback;
3. SAVEPOINT:
This command is used to save the data at a particular point temporarily, so that
whenever needed can be rollback to that particular point.
Syntax: Savepoint A;
EXPERIMENT NO. 9
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This ensures the
accuracy and reliability of the data in the table. If there is any violation between the
constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a
column, and table level constraints apply to the whole table.
The following constraints are commonly used in SQL:
FOREIGN KEY - Prevents actions that would destroy links between tables
CREATE INDEX - Used to create and retrieve data from the database very quickly
NOT NULL:
UNIQUE:
PRIMARY KEY:
FOREIGN KEY:
CHECK:
DEFAULT:
For example,
Updates applied to a Parent Table may fail if the statement leaves orphaned rows in a
child table,
INSERT command against a Child Table may fail if a matching foreign key value
does not exist in the parent table.
EXPERIMENT NO. 10
Information Schema
There are twenty different schema views in the SQL server. They are used to display
the physical information of the database, such as tables, constraints, columns, and
views. This view starts with INFORMATION_SCHEMA and followed by the View
Name.
INFORMATION_SCHEMA.CHECK_CONSTRAINTS is used to receive
information about any constraint available in the database.
A constraint is used on a particular column in a table to ensure that certain data rules
are followed for the column. INFORMATION_SCHEMA.COLUMNS is used to
receive information about the table columns such as table name, column name, the
position of the column, default value, etc. To return the views present in the current
database, INFORMATION_SCHEMA.VIEWS is used.
Catalog View
These are used to return information used by the SQL server. Catalog views provide
an efficient way to obtain, present, and transform custom forms of information. But
they do not include any information about backup, replication, or maintenance plans,
etc. These views are used to access metadata of databases, and the names and column
names are descriptive, helping a user to query what is expected.
Simple View
These views can only contain a single base table or can be created only from one table.
Group functions such as MAX(), COUNT(), etc., cannot be used here, and it does not
contain groups of data.
By using Simple View, DML operations can be performed. Insert, delete, and update
are directly possible, but Simple View does not contain group by, pseudocolumn like
rownum distinct, columns defined by expressions. Simple view also does not include
NOT NULL columns from the base tables.
Complex View
These views can contain more than one base table or can be constructed on more than
one base table, and they contain a group by clause, join conditions, an order by clause.
Group functions can be used here, and it contains groups of data. Complex views
cannot always be used to perform DML operations.
Insert, delete, and update cannot be applied directly on complex views. But unlike
Simple Views, Complex Views can contain group by, pseudocolumn like rownum,
distinct, columns defined by expressions. NOT NULL columns can be included in
complex views while they are not selected by the Simple View.
VIEW