Lab Dbms
Lab Dbms
KEY POINTS :
• It is a collection of related tables .
Table – It is a data file that stores organised data and also contains similar
records.
• Here, each row if identified as entity , then the table will be considered as
entity set.
• Horizontal lines of the table form the rows , which is also known as tuple or
records.
• Vertical lines of the table form the columns, which is also known as attribute
or fields.
• The facts describing any entity is known as data.
• The tables are stored in the database in form of a structure known as
schemas.
ILLUSTRATION :
( columns /attribute /fields)
STUDENT
Roll no name dept age
1. priya cse 21
2. riya cse 20
3. mukesh cse 22
1. ORACLE
2. DB2
3. Microsoft SQL Server
4. MySQL
5. SQLite
6. IBM Lotus
7. SQL Anywhere
8. Visual Fac Pro
9. Vertica
10.Microsoft Access
12.IBM Informix
13. Ingres
• Advantages OF RDBMS:
o Efficient data management and retrieval.
o Support for complex queries and transactions.
• Disadvantages OF RDBMS:
o Can become complex with very large or highly interconnected
datasets.
• It runs the DBMS as a process on the server and run a client database
application on each client.
• The client application sends a request for data over the network to the
server .
• When the server receives client request , the DBMS retrieves data from
the database, performs the required processing on the data , and sends
only the requested data back to the client over the network.
3- TIER ARCHITECTURE :
Three-tier architecture is a well-established software design pattern that divides an
application into three distinct layers, each responsible for specific aspects of the
application's functionality.
1. Presentation Tier:
• Function: This is the user interface layer where users interact with the
application. It displays information to the user and collects input.
• Function: Also known as the business logic layer, it processes user inputs,
makes logical decisions, and performs computations. It acts as an
intermediary between the presentation and data tiers.
3. Data Tier:
• Function: This layer is responsible for storing and managing data. It handles
database operations like querying and updating data.
• Technologies: Utilizes database management systems (DBMS) such as
MySQL, PostgreSQL, Oracle, or SQL Server.
SQL * PLUS :
SQL*Plus is an interactive and batch query tool provided with every Oracle Database
installation. It offers a command-line interface that allows users to execute SQL and
PL/SQL commands, manage database objects, and perform administrative tasks.
Key Features:
Command Execution: Users can input and run SQL statements, PL/SQL blocks,
and SQL*Plus-specific commands to interact with the Oracle Database.
• Scripting Support: SQL*Plus supports the creation and execution of scripts,
enabling automation of repetitive tasks and batch processing.
1. SAVE
3. START
4. @ (AT Sign)
• Purpose: Executes a script file containing SQL commands.
• Syntax: @ [FILE_NAME]
• Example: @myscript.sql
• Description: Functions similarly to the START command, executing the
SQL commands in myscript.sql.
5. @@ (Double AT Sign)
6. SPOOL
TYPES OF SQL :
In SQL, particularly within Oracle databases, the DUAL table is a special, single-row,
single-column table automatically created along with the data dictionary. It is owned
by the user SYS but is accessible to all users. The table has one column, DUMMY,
defined as VARCHAR2(1), and contains one row with a value of 'X'.
sql
sql
The DUAL table is a convenient tool in Oracle SQL for scenarios where a table
reference is syntactically required, but no actual table data is necessary.
---------------------------------------------------------------------
CSE22141
Regarding the term "Tab" in SQL, it does not refer to a standard concept or
command. In some contexts, "TAB" might be used as an alias or shorthand for a
table name, but it is not a reserved keyword or a predefined table in SQL.
Command in terminal :
SQL> select * from tab; Output: no rows selected
DATA TYPES :
In SQL, data types define the kind of data that can be stored in a table's columns,
ensuring data integrity and optimizing storage. They can be broadly categorized as
follows:
• Approximate Numerics:
• TIMESTAMP: Stores date and time values, often with time zone information.
In SQL, data types define the nature of data that can be stored in a table's columns,
ensuring data integrity and optimizing storage. Here's a brief overview of some
commonly used data types:
1. CHAR:
• Example: CHAR(10) reserves 10 bytes for the string, padding with spaces if
the input is shorter.
2. VARCHAR/VARCHAR2:
• Description: Stores variable-length character strings.
• Usage: Suitable for data with varying lengths, like names or addresses.
• Example: VARCHAR2(50) can store up to 50 characters, using only the
necessary space for each entry.
3. NUMBER:
• Description: Stores numeric data with optional precision and scale.
• Usage: Used for integers, decimals, and floating-point numbers.
4. DATE:
• Usage: Captures dates and times, often including year, month, day, hour,
minute, and second.
5. INTEGER:
• Description: Stores whole numbers.
6. NUMERIC:
• Description: Stores exact numeric values with defined precision and scale.
• Types:
o CLOB: Character Large Object for large text data.
o BLOB: Binary Large Object for binary data like images or videos.
• Usage: Ideal for storing extensive data that exceeds typical column size
limitations.
• Example: A CLOB can store large text documents, while a BLOB can store a
video file.
WRITE ADVANTAGE OF VARCHAR2 OVER CHAR :
In Oracle SQL, choosing between the VARCHAR2 and CHAR data types depends
on the nature of the data you intend to store. While both are used for storing
character strings, VARCHAR2 offers several advantages over CHAR:
1. Efficient Storage:
• Dynamic Length: VARCHAR2 stores strings with variable lengths, using only
as much space as needed for each entry, plus a small amount of overhead. In
contrast, CHAR is a fixed-length data type that pads shorter strings with
spaces to match the defined length, potentially leading to wasted storage
space.
2. Performance Considerations:
STUDENT
TNAME
TABTYPE CLUSTERID
STUDENT
TABLE
Or
Output ;
Name varchar2(15)
Marks number(4,2)
Values(3,’riya’,’ee’,54),
Values(4,’ritika’,’it’,32),
Values(5,’rahul’,’ece’,98);
Output:
5 rows selected .
Output :
1 avik cse 23
2 priya cse 45
3 riya ee 54
4 ritika it 32
5 rahul ece 98
** IMPORTANT NOTE **
If we enter the command in this way in the terminal –
values ( 2,’riya’,’ee’,54);
output ;
error at line 1:
ORA-00001 : UNIQUE CONSTRAINTS
## change the order of entry in the data level :
VALUES(‘avik’,1, 23,’cse’);
**IF we give the entry of one student with no department ; then it will
give error **
Eg :
VALUES(‘riki’,13,6);
Ouput ; error
CASE 1 –
VALUES( 7, ‘CSE’,33);
CASE 2-
Output ;
DESC STUDENT;
Output :
Marks number(4,2)
Mobile number(10)
Address number(10)
## DROPPING A COLUMN N :
Output :
Marks number(4,2)
Mobile number(10)
** IMPORTANT NOTE**
FOR SAVING ALL THE ENTIRE INFORMATION DATA , we have two methods –
1.use COMMIT COMMAND
2.RUN ANY DDL COMMAND at last
SQL> ROLLBACK;
Output ;
**WE CAN USE ROLLBACK AFTER DML COMMAND TO GET BACK BUT
WITHOUT USING ANY DDL COMMAND OR COMMIT COMMAND**
WHERE ROLL=1;
Output ;
SQL> COMMIT;
SQL> ROLLBACK;