SQL Query Runs Forever - sql-server-2008

SELECT *
FROM PaymentBatchItems
WHERE CreatedDate = '2016-11-03';
This query should return about 6 rows. I have watched it run for over 7 minutes and still running. I suspect there may be some inconsistent data in there, however I can't query the table to find out.
I ran
DBCC CHECKTABLE(PaymentBatchItems) WITH PHYSICAL_ONLY
and it returned no errors. Also tried
DBCC CHECKTABLE(PaymentBatchItems)
and it also returned no errors.
Any ideas how I can find what's hanging up my very simple query?

FOUND THE ISSUE!
When I was closing out my tabs at the end of the day, I discovered there were uncommitted transactions on one of the other server tabs. Rolled back the transactions and was able to query the table without issue.
Thanks everyone for your help. Sorry for the newbie error!

Look at the table structure, most likely PaymentBatchItems has a varbinary/blob column which might contain a lot of data. Instead of returning * try to return only one column.
Also use "top" for example
select top(100) * from ...

Related

When executing a query in rails, how do you view/log the actual query being executed?

I'm having trouble with a single query to one of my databases, and I think it's because the data I'm passing isn't being inserted correctly. The easiest way I can think of to try and check this would be to see the actual sql generated by my fairly simple query, which I call like so:
query = ActiveRecord::Base.connection.raw_connection.prepare(query_string)
result = query.execute(start_time, end_time)
This query, unfortunately, does not seem to log anything like queries made through activerecord - I have logged queries from before and after it, but the one made with execute says nothing at all. I know it's running the query because it does return results, just the wrong ones.
Is it failing to log the actual query because it's an execute statement? What do I need to do in order to see the actual sql query being sent out to the table here?

No database selected. MySQL Query Browser

I am using MySQL Query Browser 1.2.17. My problem is that using EXACTLY the same query sometimes I get No database selected error.
I tried to find any dependence in using USE database; or FROM database.table.
I have no idea when will I get an error and when I won't and if I get I don't know how to solve this (since there is in the query USE database;).
UPDATE AND SOLUTION:
Since the problem was independent neither on the USE database; nor FROM database.table and has been observed RANDOMLY (ex. run query, it works, then immediately run again with the same query and it didn't work anymore), I recreated the database simply filling it with data from backup and it helped.
Best practice to write query.
databasename.tablename
example
SELECT * FROM database.table where 1 = 1

mysql query works without errors in phpmyadmin but when refreshed changes are not shown

Mysql query when checked in phpmyadmin works without errors and changes are seen in the table, but when the phpmyadmin is refreshed it doesn't show changes.This query is written to sort the records in alpha numeric as order, when query written in PHP changes is shown but soon reverts back to the same unorderly table present before. I need it to arrange it in order
A1
A2
.
.
B1
B2
.
.
C1 and so on..
SELECT *FROM `supactive1` ORDER BY
CAST(Tno AS UNSIGNED)=0,
CAST(Tno AS UNSIGNED),
LEFT(Tno,1),
CAST(MID(Tno,2) AS UNSIGNED);
When running this query in phpMyAdmin or via your PHP script, you are seeing the results of this query. The query is simply a SELECT query and as such won't make changes to the table(s), but will return a result set which you are seeing.
I don't probably understand the question correctly. But if you are trying to reorder the actual table in the database then I don't think that's possible with the query you are trying to fire. The query will only sort the result and not the actual table. If you need to sort the actual table, you may need to additional things while insertion. Anyways, I think it is better to get a sorted output using a query than trying to sort the actual array.

How to delete the duplicate records from the whole database

Today I have tried to fire the job that checks for the redundancy in the particular table.
I have one table EmpDetails
Please find the screenshot to find the records in the table
A job runs from the sql in every 2 min and delete the redundancy from the table.
Result of the job: :
But my expectations from the job are some bit higher, I want from the job to check the the redudancy from the whole database not from the single table.
Can anyone please suggest me, is that really possible or not. If it is possible so what should be the right approach. Thanks in advance.
You should first define what a duplicate is. And for running across multiple DB use can either loop through the databases or you can use EXEC sp_MSforeachdb which is an undocumented sp
Thanks

DatabaseLookup hangs on specific values

I use Kettle for some transformations and ran into a problem:
For one specific row, my DatabaseLookup step hangs. It just doesn't give a result. Trying to stop the transformation results in a never ending "Halting" for the lookup step.
The value given is nothing complicated at all, neither it is different from all other rows/values. It just won't continue.
Doing the same query in the database directly or in a different database tool (e.g. SQuirreL), it works.
I use Kettle/Spoon 4.1, the database is MySQL 5.5.10. It happens with Connector/J 5.1.14 and the one bundled with spoon.
The step initializes flawlessly (it even works for other rows) and I have no idea why it fails. No error message in the Spoon logs, nothing on the console/shell.
weird. Whats the table type? is it myisam? Does your transform also perform updates to the same table? maybe you are locking the table inadvertantly at the same time somehow?
Or maybe it's a mysql 5.5 thing.. But ive used this step extensively with mysql 5.0 and pdi 4.everything and it's always been fine... maybe post the transform?
I just found the culprit:
The lookup takes as a result the id field and gave it a new name, PERSON_ID. This FAILS in some cases! The resulting lookup/prepared statement was something like
select id as PERSON_ID FROM table WHERE ...
SOLUTION:
Don't use underscore in the "New name" for the field! With a new name of PERSONID everything works flawlessly for ALL rows!
Stupid error ...