July 1, 2004 at 9:52 am
Hello,
I want generate an admin script in T-sql with SQL Analyzer but i've a problem !
[SQL ANALYZER or osql/isql]
select 'DBCC '+tablename+'+char(10)+char(13)+' GO ' from TableList
I want this :
DBCC TABLE1
GO
DBCC TABLE2
GO
...
but i've :
DBCC TABLE1 GO DBCC TABLE2 GO
could you give me the T-sql script to generate my scripts.
Regards
Guillaume.
July 1, 2004 at 10:13 am
This should do the job. The PRINT statement is better for this task than SELECT.
DECLARE C1 CURSOR
READ_ONLY
FOR SELECT tablename FROM TableList
DECLARE @tablename varchar(40)
OPEN C1
FETCH NEXT FROM C1 INTO @tablename
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT 'DBCC ' + @tablename + char(10) + char(13) + 'GO ' + char(10) + char(13)
END
FETCH NEXT FROM C1 INTO @tablename
END
CLOSE C1
DEALLOCATE C1
GO
July 1, 2004 at 10:15 am
too many '
here's the corrected version
select 'DBCC '
+tablename
+char(10)
+char(13)
+' GO ' from TableList
MVDBA
July 1, 2004 at 10:21 am
i did this
select 'DBCC '+name+char(10)+char(13)+' GO ' from sysobjects
and got
DBCC sysobjects
GO
DBCC sysindexes
GO
DBCC syscolumns
GO
DBCC systypes
GO
DBCC syscomments
MVDBA
July 1, 2004 at 10:27 pm
Try char(13)+char(10)
I had trouble trying to concatenate things in a MS Access query where CRLF pairs were needed. I first tried using char(10)+char(13) (LFCR) and absolutely NOT getting what I wanted. as soon as I reversed them, it was PERFECT. Maybe that's why they're referred to as CRLF?
Hope this helps,
Butch
July 2, 2004 at 1:23 am
Hi,
Thanks for your answers.
I tested the various solutions and the only one which functions is as
follows:
DECLARE C1 CURSOR
READ_ONLY
FOR SELECT name FROM sysobjects
DECLARE @tablename varchar(40)
OPEN C1
FETCH NEXT FROM C1 INTO @tablename
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT 'DBCC ' + @tablename + char(10) + char(13) + 'GO ' + char(10) + char(13)
END
FETCH NEXT FROM C1 INTO @tablename
END
CLOSE C1
DEALLOCATE C1
GO
--------------- Edit ------
And for your information i use the SQL Analyzer utility.
---------------- end edit --------
Thanks
July 2, 2004 at 2:03 am
Try this instead but run it from an osql window.
select 'dbcc ' + tablename + convert(char(1),0xa) + 'go'
from tablelist
Much neater and easier - old sybase trick.
July 5, 2004 at 2:29 am
Hi,
It works fine from osql utility but no from wosql.
I've Two solutions now ! one from wosql with a cursor and a print and one with osql .
Thanks.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply