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

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

Predicting whether the bank will give loan to its customers based on their credit score (Logistic Regression)

"The best thing about data is that it tells a story." - Naveen Jain Today let's have a look at another machine learning model know as Logistic Regression. Logistic Regression is a statistical model where the outcome is predicted as binary such as YES or NO, based on the previous/train_dataset. ( Please open the images in a new tab or try to zoom-in ) import required models read your dataframe visualize your dataset create Logistic Regression model split your data into train and test dataset fit your train dataset into the regression model predict future values visualize your predicted values Github link for pdf:  click here

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: flex; } .text{     padding: 30px;     margin: 10px;     letter-spacing: 1px;     box-sizing: border-box;     color: white; } .box{     top: 20%;     left: 40%;     display: flex;     position: relative;     width: 300px;     height: 420px;     justify-items: center;     align-it