Friday, February 3, 2012

Difference between drop and truncate in sql server

Hi friends here i will explain the difference between Drop and Truncate

As we have seen in the last post about the difference between Truncate and Delete today we will seen the Difference between Drop and Truncate visually 

Let's see we have the table with the following data as given below

now suppose if we perform truncate operation on it all the Records will be remove from it. as you can see it from givenn slide

Above you can see all the data will be deleted from the table but all the columns will be as it is.

Now if you use Drop Query then whole the table will be deleted
let's see the example below

so now as given above if u try  select query you have the above errors because table is not exists.

so we have conclusion is that

Drop - deletes the data as well as structure
Truncate - deletes only the data, and resets the auto increment column to 0

Wednesday, February 1, 2012

Diffrence between Stored Procedure and User Define Function in SQL

These are the main difference between Stored Procedure and User Define Function


-can be used with Select statement
-Not returning output parameter but returns Table variables
-You can join UDF
-Can not be used to change server configuration
-Can not be used with XML FOR clause
-Can not have transaction within function

Stored Procedure

-have to use EXEC or EXECUTE
-return output parameter
-can create table but won’t return Table Variables
-you can not join SP
-can be used to change server configuration
-can be used with XML FOR Clause
-can have transaction within SP

Tuesday, January 31, 2012

Difference between Truncate and Delete in SQL

Here we will see the first practical example

Suppose we have following table named as tbl_Countries

Now we will use the delete operation on given table

if we want delete specific record in table we have to use the Delete operations
with where clause

so as you have seen in above table you can delete specific row using Delete Operations

 if you want to delete all  records of the table just use the Truncate operation on your table.

so from the above example you can understand the clear difference between Truncate and Delete

Difference between delete and truncate

 Can not be rolled back.
 DML command.
 Does not reset identity of table.
 It cannot activates trigger. mention transaction log of deleted rows.

- Truncate
Can be rolled back. DDL Command reset identity of table.
 Activates trigger.
 Does not mention transaction log.

how to create dynamic page using ms sql procedure

Hello Friends ,

This post is  about how to create dynamic page using procedure in using MS sql procedure .

for that first create the simple .aspx page named as create-dynamic-page.aspx

its content would be like below image

now write down the inline code or page behind code in your page.
your code behind page that is create-dynamic-page.aspx.vb

Let's create one procedure for dynamic page that is very simple

-- exec prc_GetDynamicPageContent               
-- drop proc  prc_GetDynamicPageContent              
create  proc [dbo].[prc_GetDynamicPageContent]              
 select '<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="create-dynamic-page.aspx.vb" Inherits="default.create_dynamic_page" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">

HERE using above procedure it will create dynamic page each time in your code and will use
create-dynamic-page.aspx.vb as code behind so wite down your code in that file.

Monday, January 30, 2012

Procedure or function expects parameter ' which is not supplied

This post discuss in details at DataHaunting

Hi many of us  facing this type of problem when wroking SQL Server .

let me illustrate the example if you are working with the SQL Server

in the given example if you execute the procedure it will show the error as given below because here
we need the pass the parameter  as '@name' 

now if you are passing the parameter as 'dilip0165' your query will be execute successfully .

if you have need  number of arguments to insert into table  then you have to pass the number of
parameter as here we have passed .

Tuesday, January 24, 2012

How to find table which used in many procedures in DataBase using Procedure

This post discuss in details at DataHaunting

We Many times want to find the table which used in various procedure 
Here I have Created simple procedure to find in which Procedure it is used

CREATE PROCEDURE [dbo].[prc_Search]    
@StringToSearch varchar(100)     
   SET @StringToSearch = '%' +@StringToSearch + '%'    
   SELECT Distinct SO.Name    
   FROM sysobjects SO (NOLOCK)    
   INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID    
   AND SO.Type = 'P'    
   AND SC.Text LIKE @stringtosearch    
   ORDER BY SO.Name  

create above procedure in your Database

Now when you want find your table is used in which procedure simply Execute
   prc_Search 'tbl_AdminUsers'
as given below slide you can see the number of procedure in which your procedure is used

How To Create Table in SQL Server

There are various way we can create table in SQL Server But Here I will Discuss the convenient way to make the Data Table on SQL Server .

Here I will make the Table On SQL Server 2008 with snapshot so which is easy to understand.

As we have seen in last post that how to create Database using Server Explorer .

Today we will see how to create the Table with SQL various functionality .

in the give example we have created New Table Named as "db_test"

Now to create the table right click ont the table you will see "New Table" option click on it.

Here I have created table without any Primary Key but very useful way to create the table.

Let's see the Example 

Here we can see the I have Created simple Table with five field .
let's see the advantage of this type of Data Table

First I have Created Column "id" with data type integer here i have unchecked the allow nulls.
Now look at the column property in that focus on "Identity Specification" in that double click on is identity you will see column property as given below exmaples.

Here it will show the auto increment when add the column here "Identity Increment " specify the increment in number and "Identity Seed" specify that from where to start count for the auto increment .

so by using this simple property you can have new distinct "ID" number each time when you have create new rows . so no conflict can be generated  and  your table will work smoothly