Showing posts with label SQL SERVER. Show all posts
Showing posts with label SQL SERVER. Show all posts

Monday, 17 March 2014

How to find already exist Value in sql server

How to find already exist Value in sql server


Use this query, If you want the value, which is already exists in the database:



set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SP_insert]--(Store Procedure)
@b_Barcode varchar(100)--(Column name)
as begin
if exists (select b_Barcode from Barcode where b_Barcode=@b_Barcode)
return 0
else
insert into Barcode (b_Barcode) values(@b_Barcode)
end

Saturday, 15 March 2014

How to check SQl Server Edition .Product Version,Product Level

How to check SQl Server Edition :




with the help of this single line query you can check which Edition of server you are using:
--Query
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')


It gives you this output as below:


How to Delete All Tables Data in a single query

How to Delete All Tables Data in a single query in SQL SERVER


use this query to delete data in all tables in sql server

- disable all constraints
EXEC sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

-- delete data in all tables
EXEC sp_MSForEachTable 'DELETE FROM ?'

-- enable all constraints                                  

exec sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'