If your objective is to be a data administrator, database developer, or data analyst, then you must master SQL queries. If you want to work with structured data, then you should learn how to retrieve, handle, and analyze data from relational databases.

This comprehensive blog explores the several SQL queries that enhances your querying abilities. By the end you also understand the aspects of triggers and other functions. With that in mind, lets get started!

Some SQL question to practice

  1. Find product which is not sold once.
declare @product table(
	ProductID int,
	ProductName varchar(50)
)
insert into @product values (1,'apple')
insert into @product values (2,'orange')
insert into @product values (3,'banana')

declare @productSales table(
	ProductID int,
	TotalPrice int
)
insert into @productSales values (1,100)
insert into @productSales values (2,500)
insert into @productSales values (1,600)

select * From @product
select * From @productSales

You can use left outer join @ productSales as ps on p.ProductID = ps.ProductID

SQL Clauses

Select clause retrives data from the table. Let’s take a look on how you can take advantage of Select clauses on SQL queries.

Select Clause

Select Column1, Column2,....
From Table_name
Where condition;

Insert Clause

If the insert clause is succesful, it returns the number of tables inserted into table. That said, this query is utilized to write a rows of data into the table.

INSERT INTO table_name(Column1, Column2, ...)
VALUES(value1, value2,....)

Trigger

Trigger is a set of SQL statements that resides in a system memory with unique needs. It belongs to a specific class of stored procedures that are automatically invoked in response to a database server event. Every trigger has a table attached to it.

When to Use a Trigger?

Trigger will be helpful when we need to execute some event automatically on certain desired scenarios. For example, we have constantly changing tables and need to know the occurrence of these changes and when these changes happen.

If a primary table made any changes in such scenarios, we could create a trigger to insert the desired data into a separate table.

Also Read: JQuery Use as Javascript Library

Difference in stored procedure and user defined function

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top