RDBMS: Manages Data in The Form of Tables. Related Tables in RDBMS Have Relationships Through Common Values
RDBMS: Manages Data in The Form of Tables. Related Tables in RDBMS Have Relationships Through Common Values
RDBMS manages data in the form of tables. related tables in RDBMS have relationships through common values. Catalog
It contains data about other data. i.e., in general catalog contains the data about the directories, subdirectories and files in the system. In relation to databases, catalog contains set of schemas, which describe databases.
SQL
We have seen conceptual, external (user view), physical (internal) schemas. There are some other schemas like star, snowflake which will be useful in data warehousing. A schema contains description of objects created by a user, such as base tables, views, constraints, domains, triggers etc., which are part of a database.
SQL 2
SQL
SQL is divided into three categories.
Data Definition Language (DDL) Data Manipulation Language (DML) Data Control Language (DCL)
SQL
SQL
DDL is used to create database, create tables in it, delete tables, alter tables, define constraints, etc., DML is use to maintain (update, insert, modify) and query the data in the database. DCL is used to control the database like giving privileges to users and overall administration of the database.
SQL 4
DDL
Some of the commands (statements) in DDL are
CREATE SCHEMA CREATE TABLE CREATE VIEW CREATE CHARACTER SET CREATE COLLATION CREATE TRANSLATION CREATE ASSERTION CREATE DOMAIN
SQL
Data Types
String
Fixed length character data of n characters (maximum 2000) VARCHAR2(n) variable length character data (maximum 4000) LONG variable length character data (max 4GB). Maximum one per table. CHAR(n)
FLOAT(n)
SQL
Data Types
Date/time DATE
fixed length date and time
Logical
BOOLEAN
SQL
CREATE TABLE
It creates a new table and its columns. Syntax: CREATE TABLE table-name (
column-name datatype
[column constraint] [default value] [, column-name datatype [column constraint] [default value] .] [,table constraint] ) ;
SQL 8
SQL
SQL
10
CREATE VIEW
Creates a view of as per the requirements of user from the related tables in the database. Syntax:
CREATE [OR REPLACE] VIEW view-name AS [(column [,column .])] subquery;
SQL
12
SQL
13
Ex 1:
CREATE VIEW st_addr_vb3 AS select st_id, st_name, home_addr from student_t where st_id LIKE 2009B3%; CREATE VIEW st_addr_vb4 AS select st_id, st_name, home_addr from student_t where st_id LIKE %B4%;
Ex 2:
SQL
14
CREATE VIEW st_performance_v (st_id, st_name, course_no, sem, year, grade) AS select student_t.st_id, st_name, course_no, sem, year, grade FROM student_t, st_course_t WHERE student_t.st_id = st_course_t.st_id;
SQL
16
ALTER TABLE
ALTER TABLE is used to change table definition. Syntax:
ALTER TABLE table_name alter_table_action; where alter_table_action is on of the following:
ADD [COLUMN] column_definition ALTER [COLUMN] column_name SET DEFAULT default_value ALTER [COLUMN] column_name DROP DEFAULT DROP [COLUMN] column_name [RESTRICT] [CASCADE] ADD table_constraint
SQL 17
ALTER TABLE
CREATE TABLE course_t (
course_no char(12) not null, c_name varchar2(30), units integer CHECK (units in (1,2,3,4,5,8,18), CONSTRAINT course_pk primary key (course_no));
In the above table, if we want to add the semester number (in an academic year) the course is floated.
ALTER TABLE course_t ADD (sem_no integer); Note: not null can not be used, if already data exists in the table.
SQL 18
SQL
19
DML
Some of the commands (statements) in DML are
UPDATE INSERT DELETE SELECT
SQL
20
WILD CHARACTERS
There are 3 wild caracters(cards). * (asterisk) _ (underscore) % (percentage)
SQL
21
WILD CHARACTERS
* is used
(i) to select all columns (attributes) of a table in a SELECT statement (ii) in functions like COUNT, to count number of row selected as per the condition in the WHERE clause
SQL
22
WILD CHARACTERS
_ and % are used in the WHERE clause when an exact match is not possible. In this case ,the keyword LIKE is paired with _ and/or % continuous characters that are known to be desired matches. These are used
before the continuous characters that are known to be desired matches after the continuous characters that are known to be desired matches before and after continuous characters that are known to be desired matches
SQL 23
WILD CHARACTERS
_ is used as wild character to represent only one character. % is used as wild character to represent any number of characters.
SQL
24
Comparison operators
operator ----------= > < >= <= != or <> meaning -----------equal to greater than less than greater than or equal to less than or equal to not equal to
SQL 25
Boolean operators
Boolean operators are used in WHERE clause to join more than one condition or to negate an expression. operator meaning ---------------------AND joins two or more conditions and returns results only when all conditions are true. OR joins two or more conditions and returns results only when at least one condition is true. NOT negates an expression
SQL
26
UPDATE
Update statement is use to change the existing data in the database. Syntax:
UPDATE table-name SET {clolumn = expression [,column = expression] .} [WHERE condition]; UPDATE table-name SET {clolumn = expression/subquery [,column = expression/subquery] .} [WHERE condition];
SQL
27
UPDATE (cont.)
Ex: update st_course_t set course_no = AAOCC311 where st_id = 2007P1PS001 and course_no = AAOCGC311;
SQL
28
UPDATE (cont.)
Ex: update course_t set course_no = AAOCC311, course_title = Database Management Applications where course_no = AAOCGC311;
SQL
29
SQL
30
INSERT
Insert command is used to add/insert one or more rows to the table. Syntax: INSERT INTO table-name [(column [,column] .)] VALUES (expression [,expression] .); INSERT INTO table-name query;
SQL
31
INSERT (cont.)
Ex: st_course_t(st_id, course_no, section, sem, year) insert into st_course_t values (2007B3A7100, AAOCC311, 2, 1, 2009-10); insert into st_course_t (st_id, course_no, sem, year) values (2007B3A7100, AAOCC311, 1, 2009-10);
SQL 32
INSERT (cont.)
Ex: (cont.) insert into st_course_t select * from temp_st_course_t;
SQL
33
DELETE
Deletes all rows from a table that satisfy the condition. Syntax: DELETE FROM table-name [WHERE condition];
SQL
34
DELETE (cont.)
Ex: delete from st_course_t where st_id = 2007A7PS001 and course_no = AAOCC311; delete from st_course_t where course_no = AAOCC311; delete from st_course_t where st_id = 2007B3A7450; delete from st_course_t;
SQL
35
SQL
36
SQL
37
File types
HSAM Hierarchical Sequential Access Methods HISAM Hierarchical Indexed Sequential Access Methods HDAM Hierarchical Direct Access Methods HIDAM Hierarchical Indexed Direct Access Methods
SQL 38
INDEXES
As we have discussed, indexes have great impact on random and sequential access to base-table data. Creating INDEXES Syntax:
CREATE INDEX index-name ON table-name(col-name [,col-name] );
SQL
39
INDEXES (cont.)
Ex: cteate index sstid on student_t(st_id); create index cno on course_t(course_no); create index stcourse on st_course_t(st_id,course_no);
SQL
40
Deleting tables/views
If we dont need the tables/views that are created, then we can delete them. Before deleting the tables/views, we should delete the indexes created on them.
SQL
41
Deleting INDEXES
Syntax: DROP INDEX index-name; Ex: drop index sstid; drop index cno; drop index stcourse;
SQL
42
Deleting views
Syntax: DROP VIEW view-name; Ex: drop view st_grade;
SQL
43
Deleting tables
Syntax: DROP TABLE table-name; Ex: drop table student_t;
SQL
44
DCL
DCL is used to control the database, like giving privileges to users and overall administration of the database.
SQL
45