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 …
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 …
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 …
Sometimes , We need to know what is the structure of stored procedure ? , How many columns will be return ? So to determine this we have easy stored procedure provided by SQL Server which is sp_describe_First_Result_Set. Below is the template to run it. You can provide your stored procedure name as variable …