You might know SET ROWCOUNT is used to return exact number of records from a table.
You can set the row count,
SET ROWCOUNT 50
When you execute following statment,
SELECT * FROM dbo.RowCountTable
you will get only 50 records regardless of number of rows you have.
But what if you execute a query like that.
SET ROWCOUNT 2147500000
When you execute this, you will get following error.
Msg 1080, Level 15, State 1, Line 1
The integer value 2147500000 is out of range.
Mind you, maximum value for interger, 2,147,483,647 since 2147500000 is more than the maximum of the integer and row count is expecting a value of a interger.
So when you are passing a value to a ROW COUNT, it has to be a integer value.
Do not use something like below,
DECLARE @rccount bigint
SET ROWCOUNT @rccount
Though there won't be any issues, if you pass values less than maximum of integer, but make sure those parameters are integer.
Translate
Tuesday, March 1, 2011
Saturday, February 5, 2011
Multiple Query Plans
As my last post, this is again something I got from MongoDB.
Execution plans are vital to measure performance of your queries. How many times, you are puzzled with why that index is not using? why it is doing a scan?
In MongoDB, there is a option to view all the execution plans with query engine considered and what was used eventually.
syntax for that is db.users.find({UserID:14049}).explain(true)
explain() will tell you what is the query plan used and true parameter will give you all the query plans considered for the execution.
However, though this is a great feature to have, in case of SQL Server implementation may not be easy. In MongoDB anyway queries have one collection only and query plan is not complex
Execution plans are vital to measure performance of your queries. How many times, you are puzzled with why that index is not using? why it is doing a scan?
In MongoDB, there is a option to view all the execution plans with query engine considered and what was used eventually.
syntax for that is db.users.find({UserID:14049}).explain(true)
explain() will tell you what is the query plan used and true parameter will give you all the query plans considered for the execution.
However, though this is a great feature to have, in case of SQL Server implementation may not be easy. In MongoDB anyway queries have one collection only and query plan is not complex
Wednesday, February 2, 2011
Dropping Duplicates
If you search for "Duplicate rows sql server", in Google you will get about 136,000 results. This will tell how series the problem is. I am not going to add another post to above huge number of articles. What I going to explain here is how some other database system does this.
I was able to attend to a MongoDB conference last month and came across few features which are nice to have features in SQL Server.
In MongoDB, there are few ways for creating indexes, one is stated below.
db.users.ensureIndex({UserID:1},{"unique":true, "dropDups":true})
Just to tell you what the above script is, users is the "table" (Collection in MongoDB) and UserID is the "column" (Attribute in MongoDB") and ensureIndex is the command to create the index.
so, in this statement, unique:true will create a unique index BUT if there are duplicates records, it will retain only the first "record" ( Document in MongoDB" ) and others will be deleted because of the dropDups:true statment.
Now, this is very efficient way of deleting duplicates, but you need to pay more attention before issuing this command.
I was able to attend to a MongoDB conference last month and came across few features which are nice to have features in SQL Server.
In MongoDB, there are few ways for creating indexes, one is stated below.
db.users.ensureIndex({UserID:1},{"unique":true, "dropDups":true})
Just to tell you what the above script is, users is the "table" (Collection in MongoDB) and UserID is the "column" (Attribute in MongoDB") and ensureIndex is the command to create the index.
so, in this statement, unique:true will create a unique index BUT if there are duplicates records, it will retain only the first "record" ( Document in MongoDB" ) and others will be deleted because of the dropDups:true statment.
Now, this is very efficient way of deleting duplicates, but you need to pay more attention before issuing this command.
Saturday, January 29, 2011
Re-generating SQL Server Logins
Migrating database servers is quite a frequent task which is carried out by a DBA. In migrating, it is very important to transfer the logins. When transfering logins and users, you need to make sure that you transfer roles and password as well.
By querying the system tables, database administrators can produce a comprehensive report for login permission including original password, the server and database roles assigned, down to granular level object permission.
This article describes how to achive this and other information behind this.
By querying the system tables, database administrators can produce a comprehensive report for login permission including original password, the server and database roles assigned, down to granular level object permission.
This article describes how to achive this and other information behind this.
Friday, January 21, 2011
Tips & Tricks for DBAs Writing Their First Article
I have been writing articles from 2003 (only 7+ years not much, still more to go) in some SQL sites like www.SQLServerCentral.com ,www.sql-server-performance.com , www.sqlserveruniverse.com etc.
Brad Mc Gehee is one of few who inspired me to write articles.Now he has comeup with some tips and tricksfor writing articles.
Hope you will take a leaf out of this and start writing. Good luck.
Brad Mc Gehee is one of few who inspired me to write articles.Now he has comeup with some tips and tricksfor writing articles.
Hope you will take a leaf out of this and start writing. Good luck.
Friday, January 14, 2011
SQLskills Free Online MCM Training
These videos are designed to give an overview of the breadth of subject knowledge required, plus some indication of the depth to which you should know it.
Monday, January 10, 2011
SQL Server Data Mining with Microsoft Office Excel
Data mining is made easier with Excel. This is my first article with data mining.
Thursday, January 6, 2011
Importing dbf files
dbf files (dbase 3+, clipper or foxpro) to SQL Server is something that you won't get frequently. However, it might not be as simple as importing other data sources.
This faq by me, tells you how to do that.
This faq by me, tells you how to do that.
Wednesday, January 5, 2011
Sending Email to Different Domains using Database Mail
This FAQ tells you how to send mail to difference domains using Database Mail.
SEQUENCE in SQL Server 2011
SEQUENCE is a core new feature of SQL Server 2011 (Denali). It is a more performant, flexible alternative to the INDENTITY attribute. This article introduces sequence and demonstrates how to use it and its performance advantage.
Read my first article on Denali
Read my first article on Denali
Subscribe to:
Posts (Atom)
