Problem:- My query is slow what are the basic things I can do to get good performance without going for indexes. Solution:- May be this solution help you which I am describing here or it is possible you already aware of it. (a) Avoid function in column :-The most basic tip is avoid …
Monthly Archives: August 2014
Problem :- Sometimes it may require to determine all the available instance of SQL Server in network. Solution:- One of the easy way to determine the instance with SQLCMD. Lets understand this by following steps 1) Open dos prompt 2) write SQLCMD – L OR SQLCMD/L Above command with return instance on your machine …
Problem :- Most of the time we have one master table and one child table which content reference of master table. We have to fetch all the child column as comma separated for master table column. for example I have a product category table and product table. We want all the product as a …
As discussed in last tip #37 Dense rank having exactly same syntax like Rank the only difference between rank & dense rank is that “dense_Rank fill the gap or avoid gap in ranking means if two row set have same ranking then just after record will have just next ranking. I am taking same …
Recently, One of my friends asked How to rename a column by SQL command frankly speaking I am not used too of using this command I prefer UI interface. Lets understand this by an example. Suppose I have a users table in which there is a column with name status which should be statusId …
In last post we have discussed Row_Number() function. In similar way we have RANK function. By the name it is clear that we provide some kind of ranking for rows. It syntax is exact same like ROW_NUMBER(). Now the question comes in mind if it is same then why SQL SERVER introduce new function. …
Mostly people faced this question in interview find highest salary so I am just trying to explain different ways let us understand this by following example suppose we have following table of employees with salary Query 1:- by aggregate function SELECT MAX (fltBasicSalary)FROM @tblEmployeeSalaryWHERE fltBasicSalary IN (SELECT DISTINCT TOP 2 fltBasicSalaryFROM @tblEmployeeSalaryORDER BY fltBasicSalary …
Sometimes we require sequence column or we can a row number column so we have ROW_NUMBER() function in SQL SERVER. Lets understand this by following example In this example we have person table which have firstname, last name, middlename columns. Now we want to fetch records with a extra column ROW_Number() so we write …
As discussed in previous tip which is TIP #33 we can get random result set by using NEWID function. Now same can be achieve by using one more option which is called TABLESAMPLE. We have following syntax for it SELECT * FROM tableName TABLESAME (Number ROWS/PERCENT) For example I am using same Adventureworks database …
Hello friends, Sometimes your project require whenever a page load or user search then each time you need to show a random order or we can say different records or order. To achieve this we can use following command SELECT * FROM yourtableName order by NewID() in below snap I am fetching person table of …