Q.) What is SQL?
- With the help of it we can retrieve data from the database.
- SQL not only allows us to read the data but also allows us to write the data in the database.
- Data in the database is stored in the form of tables.
- We can Select, Insert, Update, Delete, Create, Alter, Drop and can perform many more operations on the table. And these are called as SQL Statements.
* SQL Statements are classified mainly into 4 categories:-
1) DML (Data Manipulation Language)
2) DDL (Data Definition Language)
3) DCL (Data Control Language)
4) TCL (Transaction Control Language)
* Under DML we have :-(No Autocommit)
1. Select
2. Insert
3. Update
4. Delete
5. Merge
* Under DDL:-(Allows Autocommit)
1. Create
2. Alter
3. Drop
4. Truncate
5. Flashback
* Under DCL:-(Allows Autocommit)
1. Grant
2. Revoke
* Under TCL:-(No Autocommit)
1. Commit
2. Rollback
3. Save point
- From above, we can see that DDL and DCL "Allows Autocommit". Which means that the Transaction is COMMITED and whatsoever the updates are done on any of the rows will now be saved.
- But DML and TCL takes "No Autocommit". That means once we logout of the session and then login again we no longer have the updated rows.
* The question here arises is What is Transaction?
==> Transaction is nothing but a logical unit of work done by comprising one or more queries on one or more Objects.
Moving further, there are many Objects in the database but primarily talking about a few are:-
1) Table
2) View
3) Index
4) Sequence
5) Synonym
* Now that we have come this far, lets try to retrieve data from the database.
Please note: I'm using Oracle database 19c here.
* We will be retrieving data from 2 tables namely: EMP and DEPT.
(zoom-in or click on the images to get a better view)
- As we can see the first query: "select * from emp;" is the syntax or query to retrieve rows from a table.
- And "select * from dept;" is the syntax or query to retrieve rows from second table.
- The output of first query is 14 rows while the output of the second query is 4 rows.
- We can also write "desc emp", it is a short-hand for "describe emp".
- We can see the EMP table has 8 columns and the DEPT table has 3 columns.
- "NOT NULL" which we see here is the constraint and then further we have the datatypes of each column as NUMBER, VARCHAR and DATE. (which we will see later on)
Comments
Post a Comment