Final DBMS Unit 2
Final DBMS Unit 2
CREATE
It is used to create a new table in the database.
Syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
Example: CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email
VARCHAR2(100), DOB DATE);
Data Definition Language (DDL)
DROP:
It is used to delete both the structure and record
stored in the table.
Syntax: DROP TABLE table_name;
Example: DROP TABLE EMPLOYEE;
Data Definition Language (DDL)
ALTER:
It is used to alter the structure of the database. This change could
be either to modify the characteristics of an existing attribute or
probably to add a new attribute.
Syntax:
To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
O/P
7566 JONES MANAG 2975
ER
Predicates Relational Operators
Predicates in ‘IN’ Clauses
Consider a sample table ’emp’ EMPNO ENAME JOB SALARY
where [sal between 800 and 2900]; 7782 CLARK MANAGER 2450
where [sal NOT between 800 and 7782 CLARK MANAGER 2450
Functions Description
lower() The SQL LOWER() function is used to convert all characters of a string to lower
case.
upper() The SQL UPPER() function is used to convert all characters of a string to
uppercase.
trim() The SQL TRIM() removes leading and trailing characters(or both) from a
character string.
Syntax: LOWER(string)
Example: LOWER(‘TEST’)
UPPER() function
Syntax: UPPER(string)
Example: UPPER(‘test’)
Character Functions
TRIM() function
The SQL TRIM() removes leading and trailing characters(or both) from a character string.
output: MADA
output: ADAM
output: ADA
Date Functions
Date functions in SQL:
1. NOW() : give the current system's date and time.
2. CURDATE() : give the current system's date.
3. CURTIME() : give the current system time.
4. DATE() : extract the date from the DATETIME datatype column.
5. EXTRACT():extract a specific part of date and time according to our requirements: day,
month, year, day, hour, minute, etc.
6. DATE_ADD() :add a specific time interval to the given date.
7. DATE_SUB(): remove a specific time interval from the given date.
8. DATEDIFF(): give us the number of days that fall between the two given dates.
9. DATE_FORMAT(): display the date or time-related information in a well-formatted
manner.
Conversion Functions
the conversion functions are used to convert a value from one datatype to
another.
Function Description
CAST() Is used to transform the numerical data into character or string data.
PARSE() Is used to convert a string data to the desired data format and returns
the outcome as an expression.