








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









(Questions and answer based on fourth module) (1 Mark questions)
c) NOT Logical Operator: If you want to find rows that do not satisfy a condition, you can use the logical operator, NOT.
✓ EXTRACT(): This function retrieves a field such as a year, month, and day from a date/time value. Syntax EXTRACT(field FROM source) The field argument specifies which field to extract from the date/time value. CENTURY The century DAY The day of the month (1 - 31) MONTH Month, 1 - 1 2 YEAR The year DOW The day of week Sunday (0) to Saturday (6) DOY The day of year that ranges from 1 to 366 HOUR The hour (0-23) MINUTE The minute (0-59) SECOND The second Example SELECT EXTRACT (YEAR FROM TIMESTAMP '201 6-1 2-31 1 3:30:1 5') 201 6 ✓ DATE_PART (): This function that allows you to retrieve subfields e.g., year, month, week from a date or time value. Syntax DATE_PART(field,source) Example SELECT date_part('year',TIMESTAMP '201 7- 01 - 01 '); date_part 201 7 ✓ NOW(): This function returns the current date and time. Example SELECT NOW()
LEFT(string, n) Example SELECT LEFT('ABC',1 ); left
A ✓ LENGTH() :This function returns the number of characters in the string. Example SELECT LENGTH(‘Computer’); LENGTH
8 ✓ REPLACE(): This functions that search and replace a substring with a new substring in a string. Syntax REPLACE(source, old_text, new_text ) Example REPLACE(‘malayalam’,’a’,’e’); REPLACE
Meleyelem ✓ SUBSTRING(): This function returns a part of string. Syntax SUBSTRING ( string ,start_position , length ) string is a string whose data type is char, varchar, text, etc start_position is an integer that specifies where you want to extract the substring. length is a positive integer that determines the number of characters that you want to extract from the string beginning at start_position Example SELECT SUBSTR(‘computer’,3,4); SUBSTR
RENAME COLUMN old_column_name TO new_column_name; ALTER TABLE student RENAME COLUMN dob TO d_birth
ColumnNameN data_type, CONSTRAINT Constrint_name PRIMARY KEY(coumn1,column2)); Example CREATE TABLE Sales_Order(itemcode varchar(5), orderno varchar(5), order_date date, qty int, CONSTRAINT pk_sorder PRIMARY KEY(itemcode.orderno))
a new row, PostgreSQL checks if the value is already in the table. If it finds that the new value is already there, it rejects the change and issues an error. The same process is carried out for updating existing data. The syntax for creating a unique constraint using a CREATE TABLE statement in PostgreSQL is: CREATE TABLE table_name ( column1 datatype , column2 datatype , ... CONSTRAINT constraint_name UNIQUE (columname) ); Example CREATE TABLE Customer (Custno varchar(5), Custname varchar(20), email varvar(20), mobile varchar(10), CONSTRAINT unq_email UNIQUE(email), CONSTRAINT unq_mob UNIQUE(mobile))
( 10 Mark questions)
Syntax SELECT columns FROM table INNER JOIN table ON table1.column = table2.column; Visual Illustration ➢ FULL OUTER JOIN This type of join returns all rows from the LEFT-hand table and RIGHT-hand table with nulls in place where the join condition is not met. Syntax SELECT columns FROM table FULL OUTER JOIN table ON table1.column = table2.column; Visual Illustration
SELECT ename FROM emp where salary IN (SELECT SALARY FROM emp WHERE salary>20000) Sub query with EXISTS operator A subquery can be an input of the EXISTS operator. If the subquery returns any row, the EXISTS operator returns true. If the subquery returns no row, the result of EXISTS operator is false. Sub query with ANY operator ANY operator compares a value to a set of values returned by a subquery. The sub query must return exactly one column. The ANY operator must be preceded by one of the following comparison operators =, <=, >, <, > and <> The ANY operator returns true. if any value of the subquery meets the condition, otherwise, it returns false. Example SELECT ename FROM emp where salary ANY= (SELECT SALARY FROM emp WHERE salary>20000) Sub query with ALL operator ALL operator allows you to query data by comparing a value with a list of values returned by a sub query. The ALL operator must be preceded by a comparison operator such as equal (=), not equal (!=), greater than (>), greater than or equal to (>=), less than (<), and less than or equal to (<=). Example SELECT ename FROM emp where salary >ALL (SELECT SALARY FROM emp WHERE salary>20000)