Posts

SQL Triggers and Stored Procedures

Image
  Trigger: A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs. Trigger are nothing but logic, which execute before insert, update and delete. They help us to executes preprocessing logic. Types of Triggers: 1. AFTER Trigger : AFTER triggers are fired after the SQL server finishes execution of actions like insert, update and delete fired.   Executes after the data modification. 2. INSTEAD OF Trigger : INSTEAD OF triggers are fired before the SQL server starts execution of actions like insert, update and delete gets fired.  Executes prior to data modification.  Creating Triggers  :  1. Select New Trigger from table :  2. Create trigger :  2. Execute trigger :   Stored Procedures : Stored Procedures is a block code which we can re-use. Stored procedures are pre-compiled, their syntax and plans are already checked, so it increases the performance. Inline SQL : Inline query ...

SQL Index and SQL Plan

Image
Index : Indexes are used to improve the performance of searching. An index makes a search faster by using a Balanced Tree (B-Tree) Structure.  In B-Tree Structure data divided into root node, non- leaf nodes and leaf nodes. An index is a pointer to data in a table. Indexes are special lookup tables that the database search engine can use to speed up data retrieval. Example : Index has two types which helps to search fast : 1. Clustered Index : A Clustered Index stores the actual data at the leaf node. In SQL server clustered index is created automatically, when a primary key is created. Only one clustered index is created per table. Creating Clustered Index in SQL server :   1.  Go to Design of a table, then right click on column and select Indexes/ Keys : 2.  After that in Table Designer set 'Create As Clustered' as Yes, See Clustered index is created : 2. Non-Clustered Index: The leaf nodes of non-clustered index doesn't know where the data is? Leaf node of non-clu...

ASP.NET MVC Interview Questions : Part-4

Image
  Q.1  What is dependency injection? The DI provides the objects that they needs(dependencies). DI is a design pattern used to implement IoC(Inversion of Control - Here control of object is transferred to the framework). It allows the creation of object outside the class and provides those object to class. Using DI we move creation and binding outside the class. DI pattern has 3 classes : Client class(dependent class : Depends on service class), Service class(dependency : Provide service to client) and Injector class(Injects service class object to client class). Q.2 How can we configure data from appsettings.json? We can configure using two ways :           1) Using IConfiguration :  It is available in DI container and directly access JSON properties by injecting IConfiguration in constructor of controller or class.  We can define readonly property of type IConfiguration.          2) Using options pattern :  To ...

ASP.NET MVC Interview Questions : Part 3

Image
  Q.1  How to pass model to the view? We can pass model first to controller action method then controller pass it to view.  We can pass this using ViewData, ViewBag, TempData, strongly typed model object. When we pass data to view using ViewBag, ViewData, TempData then that view becomes loosely-coupled. We can better understand by given example below: Q.2  What is strongly typed views and how do we create them? The view which bind with any model is called as Strongly-typed view. Strongly Typed views provides compile-time error checking as well as intelligence.  If we misspell the property or method name, then it will known at compile time rather than at run-time.  We need to pass model object as a parameter to view() method.  Eg. protected internal ViewResult View(object model) - This is the overloaded version of View() method which we can use to pass data from controller to view. Q.3  How we can change the startup controller name and action name...

SQL backup , restore and scripts

Image
  SQL  Backup : The backup copies the data or log records from database to device such as disc. This copy can be used to restore or recover the data after failure. Their are three main types of backup : Full backup : It is a backup of database which represent the whole database at the time the backup finished. It contains all the data in a specific database or set of filegroups.  Differential backup : It is the backup based on latest full backup of complete or partial database. Log backup : It is the backup of transaction logs that have all log records that are not backed up in previous log backup. Steps for back up database : 1) Connect to database and expand database, select the database which we want to backup : 2) Select the backup type: 3) You can add new destination and add .bak extension : 4) Click on "Ok" and the database backup completed : 5) You can check whether the backup is created successfully or not by going to destination folder : SQL  Restore : The r...

SQL Concepts-3

Image
In this blog we are going to understand some important queries... Created new database and tables for solving following queries : Union : Union removes duplicate records from data sets. Union first performs sorting operation and then eliminate duplicate records in data sets, after that they return combined data sets. Example : Union All : Union All keeps all records from each data sets. It also contains duplicate records. Example : Group By : Group by is used to group the rows that have same values or it is used to organize similar data into groups. Attribute i.e used in aggregate function cannot be in group by statement. The attribute used after group by statement and attribute used in aggregate function are only allowed if rather than this another attribute used, it shows error : Example : Order By : Order by is used to sort the data in ascending or descending order. Example : Subquery : Subquery is the query within another query and included within WHERE clause. The outer query is k...