# How can i see what sql is used

**URL:** <https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233>\
**Category:** Rails\
**Created:** [September 27, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233 "2006-09-27T17:31:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/1 "2006-09-27T17:31:37Z")

</div>

when debugging a php application I often echo the SQL statements i  
created, so i can copy and paste it for testing it in an sql browser to  
find out what went wrong.

Can i do that in rails as wel?  
Is there any way to see what sql is being submitted?

Would be very helpfull

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/2 "2006-09-27T17:53:45Z")

</div>

Remco Hh wrote:

> when debugging a php application I often echo the SQL statements i  
> created, so i can copy and paste it for testing it in an sql browser to  
> find out what went wrong.
> 
> Can i do that in rails as wel?  
> Is there any way to see what sql is being submitted?

All your queries are in log/development.log

Fred

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 6:03pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/3 "2006-09-27T18:03:23Z")

</div>

Remco Hh wrote:

> Can i do that in rails as wel?  
> Is there any way to see what sql is being submitted?

While there is probably a way to have the query echoed in your view  
(I’m afraid I don’t know what it would be), you can always find it in  
your logs. Each time you load a view, the log will print each query  
run before the view is rendered. For instance, my development.log is  
full of entries like:

```
...
[4;35;1mUser Load (0.000594)e[0m e[0mSELECT * FROM users WHERE

```

(users.id = 2) LIMIT 1e[0m  
[4;36;1mClient Load (0.000638)e[0m e[0;1mSELECT \* FROM clients  
WHERE (clients.id = 1) LIMIT 1e[0m  
Rendered shared/\_worklog (0.00322)  
history: skipped refresh request  
Completed in 0.06709 (14 reqs/sec) | Rendering: 0.03604 (53%) | DB:  
0.01685 (25%) | 200 OK [[http://localhost/work\_items](http://localhost/work_items)]

~gwendy

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/4 "2006-09-27T18:01:22Z")

</div>

If you’re in development mode, the SQL queries are all available in  
the development.log file.

Alternatively if you run script/server and keep the terminal window  
open you’ll see them live in there too.

Ross

On 9/27/06, Remco Hh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ross R.  
[www.sorrylies.com](http://www.sorrylies.com)

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/5 "2006-09-27T18:11:24Z")

</div>

> when debugging a php application I often echo the SQL statements i  
> created, so i can copy and paste it for testing it in an sql browser to  
> find out what went wrong.
> 
> Can i do that in rails as wel?  
> Is there any way to see what sql is being submitted?

Watch the log file. If you’re on unix you can “tail -f  
path/to/development.log” and you’ll see the SQL that gets run…

-philip

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [September 27, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/how-can-i-see-what-sql-is-used/70233/6 "2006-09-27T20:37:47Z")

</div>

On Sep 27, 2006, at 17:31, Remco Hh wrote:

> when debugging a php application I often echo the SQL statements i  
> created, so i can copy and paste it for testing it in an sql  
> browser to  
> find out what went wrong.
> 
> Can i do that in rails as wel?  
> Is there any way to see what sql is being submitted?

Check the logs in your log directory. You probably want development.log.

–  
Jakob S. - [http://mentalized.net](http://mentalized.net)
