LAB Experiment 1
LAB Experiment 1
INTRODUCTION TO SQL
What is Structured Query Language (SQL)
All the RDBMS systems like MySQL, MS Access, Oracle and SQL Server use SQL as their
standard database language.
Schemas And Instances
Schemas and instances determine the structure and content of a database in DBMS.
An instance is a particular set of data that aligns with the schema, whereas a schema is the logical
structure of a Database.
DATA TYPES
1. CHAR (Size): This data type is used to store character strings values of fixed length. The size in brackets determines
the number of characters the cell can hold. The maximum number of character is 255 characters.
2. VARCHAR (Size) / VARCHAR2 (Size): This data type is used to store variable length alphanumeric data. The
maximum character can hold is 2000 character.
3. NUMBER (P, S): The NUMBER data type is used to store number (fixed or floating point). Number of virtually any
magnitude may be stored up to 38 digits of precision. Number as large as 9.99 * 10 124. The precision (p) determines
the number of places to the right of the decimal. If scale is omitted then the default is zero. If precision is omitted, values
are stored with their original precision up to the maximum of 38 digits.
4. DATE: This data type is used to represent date and time. The standard format is DD- MM-YY as in 17-SEP-2009. To
enter dates other than the standard format, use the appropriate functions. Date time stores date in the 24-Hours format.
By default the time in a date field is 12:00:00 am, if no time portion is specified. The default date for a date field is the
first day the current month.
5. LONG: This data type is used to store variable length character strings containing up to 2GB. Long data can be used
to store arrays of binary data in ASCII format. LONG values cannot be indexed, and the normal character functions such
as SUBSTR cannot be applied.
Difference between Table & Database
While both databases and tables are used to store data, they have key difference.
However, the important takeout is that tables are objects inside the database, and databases
can not exist without tables.
Example: A University may have a student table that stores information about their
students, such as name, address, and phone number.
They may also have a database that stores all of the student's data in one place. This
database could then contain multiple tables, such as an CSE students table and EC students
table .
Structured Query Language(SQL) is a standard language used to create, access, and manipulate
databases, being an integral part of Database Management Systems(DBMS). SQL uses various
commands to manipulate the database and these commands are divided into 5 parts as follows :
Basic Data Types used in SQL
2. VARCHAR (length)
•Description: A variable-length character string. Only the characters entered are stored, without padding.
•Example:
3. BOOLEAN
•Description: A data type that stores TRUE, FALSE, or NULL values. Supported in PL/SQL but not directly in standard
SQL tables in Oracle.
•Example CREATE TABLE students ( student_id INT PRIMARY KEY,
student_name VARCHAR(50), course_completed BOOLEAN );
4. SMALLINT
•Description: Stores small integer values, usually ranging from -32,768 to 32,767.
•Example:
5. INTEGER or INT
•Description: Stores integer values without decimals.
•Example:
6. DECIMAL [(p[,s])] or DEC [(p[,s])]
•Description: Stores fixed-point numbers with precision (p) and scale (s).
•p: Total number of digits.
•s: Number of digits to the right of the decimal point.
•Example:
7. NUMERIC [(p[,s])]
•Description: Similar to DECIMAL, stores fixed-point numbers.
•Example:
8. REAL
•Description: Stores single-precision floating-point numbers.
•Example:
9. FLOAT(p)
•Description: Stores floating-point numbers with precision p. Higher p values mean more accuracy.
•Example:
8
12. TIME
•Description: Stores time values (HH:MM:SS format). Oracle uses TIMESTAMP to handle both date and time.
•Example:
13. TIMESTAMP
•Description: Stores both date and time values (YYYY-MM-DD HH:MM:SS).
•Example:
14. CLOB [(length)] or CHARACTER LARGE OBJECT [(length)]
•Description: Stores large character data (e.g., text documents).
•Example:
NUMBER(p, s)
•p (Precision): Total number of digits (1 to 38).
•s (Scale): Number of digits to the right of the decimal point (can be negative).
Example:
1. Storing Integers
CHARACTER [(length)] / CHAR [(length)] Fixed-length character data 1 to 2000 characters (varies by database) CHAR(5) stores "ABC "
INTEGER / INT Whole numbers -2,147,483,648 to 2,147,483,647 (4 bytes) INT stores 100000
DML Commands (Data Manipulation Language) in SQL are used to retrieve, insert, update, and
delete data in a database table. These commands directly affect the data stored in the database.
3. Delete operations
a) Removal of specified row/s
Syntax: Delete from <tablename> where <condition>;
Ex: Delete from STUDENT000 where stu_age=16;