More About SQL




In this post, We will be knowing about databases, types and basic syntax of SQL.


  • What is Database. A database is a collection of valid and structured data stored in System. 


  • What is RDBMS- RDBMS stands for Relational Database Management System. The term Relational Stands for data is stored in System in the form of Rows and Columns.


  • Database Systems - There are various database Systems such as MYSQL, SQL server, Oracle which is used to stored , manipulate and maintain data.


  • What is a Table- a table is a collection of rows and columns in which data is stored.
For exercise purpose , We will be considering below table Named Detail

ID Name

City
1 Raj

Mumbai
2 Rahul

Nashik
3Saurabh

Nagar

The Basic Commands Syntax in SQL.




SELECT - used to retrieve records from database.


Syntax

select column_name from table_name





Example

select Name from Detail.                -will display all names from Detail table.



If you want to select all the columns then you can use "*"

select * from Detail                                          -will display all rows and columns from Detail Table.



INSERT - used to Insert records into database.


Syntax -

INSERTinto table_name (column name_1,column_name_2)
values (value_1,value_2)



Example -


Insert into Detail (ID,Name,City) values(3, 'Rajendra', 'Thane')



If you are inserting values in all columns then you can eliminate column names

Insert into Detail values(5, 'Gaurav' 'Nashik')



Using DISTINCT - if you want to retrieve unique values from some column of a table , then it can be achieved by using DISTINCT

Syntax

select DISTINCT column_name from table_name


ID Name

City
1 Raj

Mumbai
2 Rahul

Nashik
3 Saurabh

Nagar
4 Abhiraj

Nagar



Query - Select Distinct City from Detail

Result

Mumbai
Nashik
Nagar
More About SQL More About SQL Reviewed by vishal on August 02, 2017 Rating: 5

No comments