Skip to main content

Posts

Showing posts with the label sql index

5 Best Ways to Compare 2 DateTime - [SQL Server]

How to compare two datetime using SQL Server? This article introduces for  comparing two datetime in SQL Server and let’s explores in detail query examples as, => BASIC DATE COMPARISON --USING DATE FORMAT SELECT * FROM Customer WHERE CreatedOn > '2016-12-02' --USING DATETIME FORMAT SELECT * FROM Customer WHERE CreatedOn >= '2016-12-02:00:00:00' --USING DATE FORMAT SELECT * FROM Customer WHERE CreatedOn >= '2016-12-02' => OTHER WAYS TO COMPARE --USING DATE FORMAT SELECT * FROM Customer WHERE CreatedOn >= '2016-12-02' AND CreatedOn <= '2015-12-02' --USE OF BETWEEN OPERATOR. SELECT * FROM Customer WHERE CreatedOn BETWEEN '2016-12-02' AND '2015-12-02' I hope you are enjoying with this post! Please share with you friends!! Thank you!!!

What is @@ERROR in SQL? When we should use @@ERROR?

What is @@ERROR in SQL? @@ERROR returns only current error information (error number and error) after T-SQL statements executed. @@ERROR returns 0, if the previous SQL statement has no errors otherwise return 1. @@ERROR is used in basic error handling in SQL Server and @@ERROR is a global variable of SQL and this @@ERROR variable automatically handle by SQL. If error is occurred set error number otherwise reset 0. It is work only within the current scope and also contains the result for the last operation only. Syntax : - @@ERROR   Return Type : - INT When we should use @@ERROR? 1.       While executing any stored procedures 2.       In the SQL statements like Select, Insert, Delete and Update etc. 3.       In the Open, Fetch Cursor. When we should use Try Catch Block? The Try Catch Block is generally used where want to catch errors for multiple SQL statements. ...

What is clustered Index? How to create clustered Index?

What is clustered Index? 1.       The clustered Index is created automatically on primary key column. 2.       One table can only create one and only clustered Index. 3.       Clustered index is sorting all the rows physically. 4.    Clustered index is works based on the Binary tree concept. How to Create Clustered Index? -- CREATE CLUSTERED INDEX CREATE CLUSTERED INDEX Indexname_EmlloyeeClust ON Employee (     [EmpName] ASC or DESC ,     [EmpDepartment] ASC or DESC ) -- OR -- CREATE CLUSTERED INDEX CREATE CLUSTERED INDEX Indexname_EmlloyeeClust ON Employee (    [EmpName] ASC ,    [EmpDepartment] ASC ) WITH ( PAD_INDEX   = OFF , STATISTICS_NORECOMPUTE   = OFF , SORT_IN_TEMPDB = OFF , IGNORE_DUP_KEY = OFF , DROP_EXISTING = OFF , ONLINE = OFF , ALLOW_ROW_LOCKS ...

What is Index? How do database indexes work? How do indexes help, Types?

What is an index in SQL? An index is created in a table to increase the performance of queries and the data pages are stored contiguously when the index is created and when the index is new-built. Index allows us to retrieve very fast data from the database and allow us to searching millions of records quickly. How do database indexes work? There are some strategies that make indexes work, 1.       Optimize your code. 2.       Restructure your data. 3.       Compress your data. 4.       Materialize them. 5.       Redundancy How do indexes help? For Example, suppose is a student and studying a book and this book contains 10,000 pages. In the first day I read some topic “abc” and next day I want to read some another topic “pqr”. I will never manually go through page by page.  It is very difficult to go there. In this situation, I a...