Thursday, September 22, 2005

Query Analyzer Trick

In Query Analyzer you can save a lot of time by using this trick instead of typing all the column names of a table
Hit F8, this will open Object Browser
Navigate to DatabaseName/TableName/Columns
Click on the column folder and drag the column folder into the Code Window
Upon release you will see that all the column names are in the Code Window


Joe Muka said...

Hi, Nice site. My small site about low carb recipes is sometimes a pain to keep up with and needs work. Good job!

Anonymous said...

Nice trick, I don't know why I didn't find out about it before.

Anonymous said...

Thats the best trick, ever!

Anonymous said...

Maybe if Joe spent more time maintaining his site rather than promoting it in irritating ways, it wouldn't be such a pain for him to keep up with.

Anonymous said...

Thanks allot for that one ! :)

Anonymous said...

Unfortunately it doesn't enclose the column names in square brackets, so when you have column names with spaces or special characters you have to manually correct them.

Anonymous said...

Nice trick -- how does one find stuff like this. I had to write a stored procedure, but it is a little more flexible: you can add a string to the beginning of each column name.

CREATE PROCEDURE [dbo].[collist] @tab varchar(128), @heads varchar(128) = ''
declare @i as int
declare @tid as int
declare @nm as varchar(128)
declare @str varchar(8000)
select @tid = object_id(@tab)
if @tid is not null
declare mc cursor for
select '[' + name + ']' from sys.syscolumns
where id = @tid
order by colorder
open mc
fetch next from mc into @nm
if datalength(@nm) > 0
select @str = @heads + @nm
fetch next from mc into @nm
while @@fetch_status <> -1
if datalength(@nm) > 0
select @str = @str + ', ' + @heads + @nm
fetch next from mc into @nm
close mc
deallocate mc
select 'Columns' = @str

kakusan said...

Thank you for the nice little trick. That helps a lot. I wonder how to drag the column from Sybase SqlAnywhere. Would really appreciate it if you can come up with another trick for that.