Basic SQL Commands
Basic SQL Commands
Constraints => Constraints are used to limit the type of data that can go into a
table. This ensures the accuracy and reliability of the data in the table.
Entity - UNIQUE, NOT NULL, PRIMARY KEY
Referential - FOREIGN KEY
Domain - NOT NULL, CHECK
DUAL- Table with 1 one row and column each with datatype varchar(1)
eg of operations- select lower('RAM') from dual;
select upper('ram') from dual;
eg
SELECT empName, TO_CHAR(empDOB, 'MON-YYYY-DD') FROM demoDate1
SELECT empName, TO_CHAR(empDOB, 'MON/YYYY/DD HH:MI:SSPM') FROM demoDate1;
TO_DATE()- Converts string into date data type. It shows the format in which date
will be inserted
eg
INSERT INTO demoDate1 VALUES ('RAMA', TO_DATE('JUL-15-2010', 'MON-DD-YYYY'));
INSERT INTO demoDate1 VALUES ('RAVI', TO_DATE('1950-01-20 10:30:15PM', 'YYYY-MM-DD
HH:MI:SSPM'));
ÀGGREGATE FUNCTIONS
* SUM()/ MAX()/ MIN()/ AVG()/ COUNT()/ COUNT(*)
* Count(*) is the only aggregate function that considers NULL values.
GROUP BY Clause
* used to make the grouping of records within a table.
HAVING Clause
* used to provide condition on groups.
* used with GROUP BY clause
TRUNCATE Command- It deletes all records from the table including its structure
ON DELETE CASCADE- If the records in the parent table are deleted then the related
records in the child table will also be deleted automatically.
ON DELETE SET NULL- If the records in the parent table are deleted then the related
values (i.e. values of foreign key) in the child table will be set NULL
automatically.
NESTING OF QUERIES:
* A query within another query.
* First the inner query is executed, the result of inner query works as input to
the outer query.