Hi.
Is there any simple way to copy an object ( table,view, procedure) and write
it with another name or different owner. A new object should have the same
CONSTRAINTS, IDENTITY column etc.. For tables I've tried to create a new
table and later add columns or change data type with ALTER, but there are to
many exceptions for ALTER command and it does not work properly. I need to
synchronize a structures of one table with another or create a copy if it
does not exist yet in sysobjects and ...all those things must be done
automatically in the stored procedure:)
Thanks for help.
Toosietoosie
I'd backup the database a nd restore with a new name
The next step is changing an owner of the objects
--This script changes all objects that don't have 'dbo' to 'dbo' owner.
SELECT 'EXEC sp_changeobjectowner '''+ROUTINE_NAME+''',''dbo'''
FROM INFORMATION_SCHEMA.ROUTINES
WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_SCHEMA+
'.'+ROUTINE_NAME),
'IsMsShipped')=0
AND ROUTINE_SCHEMA != 'dbo'
After the objects have changed you can run a cusros through to alter
their names
SELECT 'ALTER TABLE '+t1.name+ ' new name'
FROM sysobjects t1
INNER JOIN sysindexes t2
ON t1.id = t2.id
WHERE t2.indid <= 1
AND t2.rows > 0
AND OBJECTPROPERTY(t1.id,'IsUserTable') = 1
"toosie" <toosie@.wp.pl> wrote in message
news:d2tjor$1pbi$1@.news2.ipartners.pl...
> Hi.
> Is there any simple way to copy an object ( table,view, procedure) and
write
> it with another name or different owner. A new object should have the
same
> CONSTRAINTS, IDENTITY column etc.. For tables I've tried to create a new
> table and later add columns or change data type with ALTER, but there are
to
> many exceptions for ALTER command and it does not work properly. I need to
> synchronize a structures of one table with another or create a copy if it
> does not exist yet in sysobjects and ...all those things must be done
> automatically in the stored procedure:)
> Thanks for help.
> Toosie
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment