Skip to main content

Introduction to SQL

 Q.)  What is SQL?

Ans.) SQL(Structured Query Language) is a standardized language to communicate with the database. 

  • 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  describe the contents of the table by a command "describe emp" and "describe dept".




  • 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)
(But for now we will be writing queries for retrieving a desired data on the sample based questions.)
 
* SQL is not Case-sensitive

Quora link: pratikbawanesspace

Comments

Popular posts from this blog

Glowing Border effect using html/css

  {html code} <html>     <head>         <link href='E:\html\.vscode\.vscode\style.css' type='text/css' rel='stylesheet'>         <title>Glowing Border</title>     </head>     <body>         <div class='box'>             <div class='text'>             <h2><u>Glowing Border</u></h2>             <p>HTML and CSS are technically not the programming languages, they are the scripting languages.              Usually used for the front-end development.</p>             </div>         </div>             </body> </html> {css code} body{     background: black;     display: ...

What are some methods for optimizing Oracle databases for large data inserts?

 For large data inserts I can suggest you few things like: Use trigger(PL/SQL) Use APPEND hint Remove indexes on tables Firstly, while you use triggers in the table it could leave data to be logically corrupt. And it will then perform insert in a very conventional way. Which is a time consuming process and won’t helps us! Secondly, using APPEND hint will help us to an extend. So, APPEND hint tells the optimizer to perform a direct-insert into the table, which improves the performance. Now there is a way which we could achieve this by minimizing the Redo generation. What Redo do is; it basically ensures the recoverability of data to the database. It writes down every transaction to the archive log. Let’s take a scenario, where if the database is running on the NOARCHIVELOG mode, using APPEND hint will reduce the redo generation i.e; it won’t write into the archive log anymore and thus increases the speed. But then it won’t be able to recover at any point in time if your data is ambi...

Stock Market using Python

 "The stock market is a device for transferring money from the impatient to the patient." - Warren Buffett Today we'll look into few ways for accessing the stock market. And we'll do this using Python ! Now, as we know that there are 2 stock exchange in India; BSE and NSE So we'll get the data from both! To begin with let's access the data from BSE first. (P.S: I certainly like the 2nd and the 3rd method to access stock market!) * So, to import the BSE data we need to " pip install bsedata ". => And then import the module, => Create an object to store the Driver Class => Then we need to do " getQuote('script_code')" where we need to provide a script code of a company which we need to access. Just like here we have given; => And from here we can see that the script code was for the company named "V-MART". But we can't remember all the script code hence we need to download this script file from the BSE websi...