DEV Community

technonotes-hacker
technonotes-hacker

Posted on

SQL - History - A Journey

  • RDBMS language.
  • Its ANSI --> standard language for operational relational databases.
  • Efficient , easy to learn and use.
  • Functionally complete.

How SQL Works

  • Data Sublanguage.
  • works with logical level.
  • common language for all relational databases.

SQL Statement types

  • Data Manipulation Language DML

Image description

  • Data Definition Language DDL

Image description

  • Data Control Language DCL

Image description

  • Transaction Control Language TCL

Image description

Oracle SQL Development Environments

  • Below are the Tools used for SQL:
  • Oracle SQL Developer --> debug , export , view reports ,etc
  • SQL Plus --> Batch query tool.
  • Oracle JDeveloper --> Multi-platform tool for web services.
  • Oracle Application Express --> Like a web browser.

Oracle SQL Developer

Image description

Concept on RDMS ( Relational Database Management Systems )

  • Relational Database --> Collection of relations or two-dimensional tables controlled by server processes.
  • Before entering RDMS , What is Data Model ? Image description
  • Entity Relationship Model --> its business specifications.
  • Then Modelling conventions --> its called Entity Relationship Modelling conventions.

Image description

  • Relating Multiple Tables --> 1. Each row is unique by primary key 2. Logically a foreign key can be related with multiple tables.

Image description

Image description

HR Schema Model

Image description

Image description

SQL Statement

  • Not case sensitive.
  • one line or more lines.
  • keywords can't be across lines or it can't be abbreviated.
  • Clauses used in separate lines , what is clause here ? The main clauses are SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, INSERT, UPDATE, DELETE, and JOIN. [ TBD ]
  • We can use indents so that one have better enhanced readability.

Image description

  • dualis a table created by Oracle Database and its owned by SYS.
  • dual as one column called DUMMY( data type VARCHAR (1)) and contains one row with value x.
  • we can use to compute some expressions.
select * from dual;
select sysdate from dual;
Enter fullscreen mode Exit fullscreen mode

Image description

Arithmetic Expression

  • +
  • "-"
  • *
  • /

Image description

  • It reads from LEFT to RIGHT. L--->R

Image description

  • You can see the difference after using Parenthesis.
select first_name,2*(salary+300), 2*salary+300 from hr.employees;
Enter fullscreen mode Exit fullscreen mode
  • NULL--> what is the value of it ? its like unavailable , unassigned , unknown or inapplicable.
  • NULLis not as same as ZERO or BLANK SPACE.

Image description

Image description

Column Aliases

  • Rename the column headings
  • Column followed by AS.
  • without AS also you can declare.

Image description

  • In the column name , it becomes CAPS. To avoid this you can use "" for AS like below,

Image description

-- select first_name AS name , last_name as father_name from hr.employees;
select first_name AS "name" , last_name as "father_name" from hr.employees;
select first_name first  , last_name last  from hr.employees;

Enter fullscreen mode Exit fullscreen mode

Image description

Concatenation Operators

  • To link the column or character strings to other column.
  • ||

Image description

select first_name||last_name AS "name"  from hr.employees;
Enter fullscreen mode Exit fullscreen mode

Literal Character Strings

  • Its a character , number or a date included in the select statement.
  • Date & character should be enclosed with single quotation marks.
  • Each character string is the output of each row.

select first_name || ' of ' || last_name OUTPUT from hr.employees;

Image description

Alternate Quote Operator

  • we can use own quotation mark delimiter.
  • specified with 'q'.
  • To increase the readability.
select department_name || q'[ Departments Name is :]' || manager_id "Department and Manager" from hr.departments ;
select department_name || 'Departments Name is :' || manager_id "Department and Manager" from hr.departments ;
Enter fullscreen mode Exit fullscreen mode

Image description

DISTINCT Keyword

  • default select query will display all rows irrespective of duplicate rows.
  • To eliminate the duplicate we can use DISTINCT keyword.

Image description

Image description

-- select department_id from hr.employees ;
select distinct department_id from hr.employees ;
Enter fullscreen mode Exit fullscreen mode

DESCRIBE Command

  • Its not a KEYWORD.
  • To display table structure.
  • Alternatively we can see in SQL developer in the column Tabs.

Image description

ORACLE QUESTIONS FOR CLEARING THE LEARNING EXAM

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Image description

Top comments (0)