0% found this document useful (0 votes)
11 views2 pages

Basic SQL Commands

The document provides an overview of SQL commands and database concepts, including constraints, data types, and various SQL operations. It explains the purpose of constraints, types of SQL commands (DDL, DML, TCL, DCL), and functions like TO_CHAR and TO_DATE for date manipulation. Additionally, it covers aggregate functions, grouping records, and nesting queries for complex data retrieval.

Uploaded by

PS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Basic SQL Commands

The document provides an overview of SQL commands and database concepts, including constraints, data types, and various SQL operations. It explains the purpose of constraints, types of SQL commands (DDL, DML, TCL, DCL), and functions like TO_CHAR and TO_DATE for date manipulation. Additionally, it covers aggregate functions, grouping records, and nesting queries for complex data retrieval.

Uploaded by

PS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

select * from all_users;

select * from tab OR select * from user_tables;


select * from user_constraints;
describe <tablename>;

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

Types of constraints based on place


Column level- NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK (it is the only
constraint where column name is used twice), DEFAULT
Table level- UNIQUE, PRIMARY KEY, 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;

DATE datatype - Default is DD-MON-YYYY


TO_CHAR(): It converts the value into the character string. It shows how to
represent date in the output

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'));

DDL Commands -CREATE, ALTER, DROP, TRUNCATE


DML Commands-SELECT, DELETE, UPDATE, INSERT
TCL- COMMIT, ROLLBACK
DCL- GRANT, REVOKE

À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.

You might also like