Showing posts with label thatcontains. Show all posts
Showing posts with label thatcontains. Show all posts

Friday, March 30, 2012

Replacing columnn name programmatically

Hi,

The following script does not return any resultset against a test db
while I know for a fact tables with letter "aaa" has columns that
contains "ccc".
What's wrong? the the inner cursor?

Thanks.

-- get all tbls with letter aaa
declare @.tbl varchar(8000)
declare tblCursor cursor for
SELECT name
FROM sysobjects
WHERE xtype = 'U'
AND name LIKE '%aaa%'

open tblCursor
fetch next from tblCursor
into @.tbl

while (@.@.fetch_status = 0)
begin

-- get all columns with letter ccc and replace it with nothing /
remove it
declare @.tbuffer varchar(4000)
declare @.cbuffer varchar(8000)

declare abnormal_cols cursor for
SELECT o.name, c.name
FROM sysobjects o
JOIN syscolumns c ON o.id = c.id
WHERE o.xtype = 'U'
AND c.name LIKE '%ccc%'
and o.id = object_id('+@.tbl')
-- ORDER BY c.name

open abnormal_cols
fetch next from abnormal_cols
into @.tbuffer,@.cbuffer

while (@.@.fetch_status = 0)
begin
-- EXEC sp_rename '+@.tbuffer+'.['+@.cbuffer+']','+Replace(+@.cbuffer+','%ccc%','')',
'COLUMN';
-- test
print @.tbuffer + ', ' + @.cbuffer;
fetch next from abnormal_cols
into @.tbuffer,@.cbuffer
end

close abnormal_cols
deallocate abnormal_cols;

fetch next from tblCursor
into @.tbl

end
close tblCursor
deallocate tblCursor;Hi

I can't see why there are two cursors here, try:

SELECT o.name, Replace(c.name,'ccc','') as NewName, c.name as OldName
FROM sysobjects o JOIN syscolumns c ON o.id = c.id
JOIN syscolumns a ON o.id = a.id
WHERE o.xtype = 'U'
AND c.name LIKE '%ccc%'
AND a.name LIKE '%aaa%'

John

"Doug Baroter" <qwert12345@.boxfrog.com> wrote in message
news:fc254714.0310211451.2f59f9c4@.posting.google.c om...
> Hi,
> The following script does not return any resultset against a test db
> while I know for a fact tables with letter "aaa" has columns that
> contains "ccc".
> What's wrong? the the inner cursor?
> Thanks.
>
> -- get all tbls with letter aaa
> declare @.tbl varchar(8000)
> declare tblCursor cursor for
> SELECT name
> FROM sysobjects
> WHERE xtype = 'U'
> AND name LIKE '%aaa%'
> open tblCursor
> fetch next from tblCursor
> into @.tbl
> while (@.@.fetch_status = 0)
> begin
> -- get all columns with letter ccc and replace it with nothing /
> remove it
> declare @.tbuffer varchar(4000)
> declare @.cbuffer varchar(8000)
> declare abnormal_cols cursor for
> SELECT o.name, c.name
> FROM sysobjects o
> JOIN syscolumns c ON o.id = c.id
> WHERE o.xtype = 'U'
> AND c.name LIKE '%ccc%'
> and o.id = object_id('+@.tbl')
> -- ORDER BY c.name
> open abnormal_cols
> fetch next from abnormal_cols
> into @.tbuffer,@.cbuffer
> while (@.@.fetch_status = 0)
> begin
> -- EXEC sp_rename
'+@.tbuffer+'.['+@.cbuffer+']','+Replace(+@.cbuffer+','%ccc%','')',
> 'COLUMN';
> -- test
> print @.tbuffer + ', ' + @.cbuffer;
> fetch next from abnormal_cols
> into @.tbuffer,@.cbuffer
> end
> close abnormal_cols
> deallocate abnormal_cols;
> fetch next from tblCursor
> into @.tbl
> end
> close tblCursor
> deallocate tblCursor;

Wednesday, March 7, 2012

repair torn page?

I have inherited a poorly administered/maintained database that
contains the following error:

"I/O error (torn page) detected during read at offset 0x000018ee23e000
in file 'F:\Program Files\ISS\RealSecure SiteProtector\Site
Database\Data\RealSecureDB.mdf"

I do not have database backups and so therefore cannot restore from
them. I want to move the database to a new platform and somehow
repair the torn page. Is this possible?
>I have inherited a poorly administered/maintained database that
>contains the following error:
>"I/O error (torn page) detected during read at offset 0x000018ee23e000
>in file 'F:\Program Files\ISS\RealSecure SiteProtector\Site
>Database\Data\RealSecureDB.mdf"
>I do not have database backups and so therefore cannot restore from
>them. I want to move the database to a new platform and somehow
>repair the torn page. Is this possible?

If you want to get your data out of this damaged database, we can help
you. Have a look at www.sql-server-repair.com

The error message you got indicates that a data page (8kByte) has not
been written completely. So at this page will be some data loss.

Regards

Thilo Immel
The SQL Sevrer Druid www.sql-server-repair.com|||You might try DBCC CHECKDB, if you haven't already done so. The end of the
report will suggest the DBCC CHECKDB repair option needed to correct the
problem. As Thilo said, this will likely be REPAIR_ALLOW_DATA_LOSS due to
the torn page. See the Books Online for more information.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"bbbad_999" <bericks999@.yahoo.com> wrote in message
news:6c6096fb.0408201308.7e1a5645@.posting.google.c om...
> I have inherited a poorly administered/maintained database that
> contains the following error:
> "I/O error (torn page) detected during read at offset 0x000018ee23e000
> in file 'F:\Program Files\ISS\RealSecure SiteProtector\Site
> Database\Data\RealSecureDB.mdf"
> I do not have database backups and so therefore cannot restore from
> them. I want to move the database to a new platform and somehow
> repair the torn page. Is this possible?|||see
http://www.nigelrivett.net/RecoverCorruptDatabase.html

Nigel Rivett
www.nigelrivett.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!