Skip to main content

Posts

Showing posts with the label EXISTS in SQL Server

15 Best Tips To Optimizing SQL Stored Procedures [How To]

Stayed Informed – Best SQL Server Tutorials with Examples 1.       Try to use stored procedures instead of bulky queries. 2.       Try to avoid using temporary tables inside your stored procedures. 3.       Try to avoid using DDL statements inside your stored procedure. 4.       Try to use “ schema name ” with “ object name ”.  For examples as, n   SELECT * FROM [dbo] .[ Users] -- Preferred this method. Instead of below n   SELECT * FROM Users – Try to avoid this method. n   --For calling stored procedure with name like, n   EXEC  [ dbo] .[uspGetUser ] -- Preferred this method. n   --Instead of n   EXEC   uspGetUser  – Try to Avoid this method. 5.       Try to call stored procedures using their fully qualified name. For examples as, n   Use IF EXISTS ...

SQL Server - Data Types

Main categories of SQL Server Data Types, 1.       Numeric  a.       Exact Numeric  b.       Approximate Numeric  2.       Date and Time  3.       Character String  a.       Non-Unicode Character String  b.       Unicode Character String  4.       Binary  5.       Others The following detail as given below, DATA TYPES SYNTAX DESC Integer            INTEGER          It is integer data type and used to specify an integer value. Smallint SMALLINT It is small lint data type and used to specify small integer value. Numeric NUMERIC(X, Y) It ...

What is @@IDENTITY in SQL? When we should use and scope of @@IDENTITY?

What is @@IDENTITY in SQL? The @@IDENTITY is a system function which returns the last inserted identity value. All the @@IDENTITY, SCOPE_IDENTITY and IDENT_CURRENT are similar functions because all are return the last inserted value into the table’s IDENTITY columns. The @@IDENTITY and SCOPE_IDENTITY return the current session last identity value but the SCOPE_IDENTITY returns the current scope value. What is the scope of @@IDENTITY? In the @@IDENTITY, there are no any limitations for a specific scope. Syntax : - @@IDENTITY    Return Type : - numeric ( 38 , 0 ) For example as, -- USE OF @@IDENTITY INSERT INTO ContactType(Code, Description, IsCurrent, CreatedBy, CreatedOn) VALUES ( 'IT-PROGRAMING' , 'This is a Prrogrammer!' , 1 , 'Anil Singh' , GETDATE()); GO SELECT @@ IDENTITY AS 'COL_IDENTITY' ; GO The Use of  SCOPE_IDENTITY :- -- DECLARE RETURN TABLE DECLARE @Return_Table TABLE (Cod...