SQL Tutorial with Example

SQL stands for Structred Query Language. SQL is database language which helps to interact with Relational Database.With the help of SQL we can create, select and manupulate database. In this sql tutorial, I have covered sql topics with example and queries. I have also shared Frequently asked SQL Interview Questions with Answers. In this Tutorial you will also get Practice Sheets and QUIZ Questions with Answers.

Insert Command in SQL Server

Insert command is used to insert data into database. There are many ways to insert data using insert command and these are following:-

Take table employee having two columns Emp_id and Emp_name

SQL Insert Command

Select Statement in SQL Server

Select command in sql is used to retrieve the data from tables. In this Article we will only discuss how to use the select statement. See the following table which will be used in the select statement:

SQL Select command

IS Null in SQL

Null is undefined value. If do not have any data for any column and we also don’t have any default value for that column, then we insert null in that column......

SQL is null

Constraints in SQL

Data integrity ensures that the data which is going to enter in the database is reliable, accurate and consistent. Data integrity maintains the correctness and completeness of data.

SQL Constraints

Primary Key V/S Unique Key

Difference between primary key and unique key are as follows: -


Primary Key V/S Foreign Key

Difference between primary key and Foreign key are as follows: -

Primary key v/s foreign-key

Delete V/S Truncate

Both commands are used to remove data from tables but they have following differences: -

delete v/s truncate

Aggregate Function in SQL

Sql is having so many predefined function and aggregate functions are also part of it. These functions are used to summarize the output. For example, if we want to sum any column, find out the maximum or minimum etc. then we can use these functions.

sql aggregate function

Like in SQL

Like operator in SQL is very important and it is used to search or match the pattern.

sql like

group by in sql

Sometimes you need to show data in some groups with some aggregate function. In this situation you can use group by statement.

sql group by

order by in sql

If we want to sort the data on the particular column in that case we use order by command. We can sort data either in ascending order or in descending order. By default order by command sorts data in ascending order.

sql order by

Case Statement in sql

Sometimes we need to show the data of table in different way at runtime. In this situation we can use case statement with select query.

sql case

Range in sql

Range operators are those operators which selects data according to particular range. There are two type of range operator and these are following:-

sql range

Top in sql

The top command is used to select the top value from the table. We have to give the number of row with the top command.

sql top

Join in SQL Server

When we need to select data from more than one table then we can use joins in SQL Server. We can join two or more tables on the basis of common column between these tables.

sql join

Stored Procedure in SQL Server

The stored procedure is a set of SQL Statements. In stored procedure we can accept the input and return the output. It is pre compiled object. Stored procedure increases the performance of the database as they are pre-compiled.

stored procedure

Stored Procedure V/S Function

There are following difference between stored procedure and user defined function:-

stored procedure v/s function

Triggers in SQL

Triggers can be defined as an area of code Which executes in response of a particular action like insert, update, delete, Create, drop etc. Triggers executes automatically


XML in SQL Server

When we need to store data in SQL Server in XML format .in this situation we can use XML Data Type.

xml in sql