The following example shows how you can use a macro in a schema script to drop existing tables before the schema is generated on a SAP ASE target server:
%ForEachTable() { if exists (select * from sysobjects where id = object_id('dbo.%tablename') and sysstat & 0xf = 3) drop table dbo.%tablename GO }
The expanded code is generated and executed with the GO statement during schema generation:
if exists (select * from sysobjects where id = object_id('dbo.MOVIE_RENTAL_RECORD') and sysstat & 0xf = 3) drop table dbo.MOVIE_RENTAL_RECORD GO if exists (select * from sysobjects where id = object_id('dbo.MOVIE') and sysstat & 0xf = 3) drop table dbo.MOVIE GO if exists (select * from sysobjects where id = object_id('dbo.MOVIE_COPY') and sysstat & 0xf = 3) drop table dbo.MOVIE_COPY GO if exists (select * from sysobjects where id = object_id('dbo.CUSTOMER') and sysstat & 0xf = 3) drop table dbo.CUSTOMER GO
Copyright © 2017 erwin Inc.
All rights reserved.
|
|