Sync Script Generation with validation
sarathi.vasudevan@verint.
Posts: 4
Hi,
Did this SQL compare 8 version supports check for existence and create or modify or drop objects?
This will be very useful, if you run the script again and again.
Thanks in advance.
Example:
if exists (select 1 from information_schema.columns
where table_name = 'TABLENAME' and column_name = 'COLUMNNAME')
begin
print 'Column NAME already exists in table TABLENAME. Not added in this migration...'
end
else begin
print 'Adding column COLUMNNAME to table TABLENAME...'
alter table TABLENAME
add COLUMNNAME int NOT NULL
CONSTRAINT CONSTRAINTNAME DEFAULT -1
end
go
Did this SQL compare 8 version supports check for existence and create or modify or drop objects?
This will be very useful, if you run the script again and again.
Thanks in advance.
Example:
if exists (select 1 from information_schema.columns
where table_name = 'TABLENAME' and column_name = 'COLUMNNAME')
begin
print 'Column NAME already exists in table TABLENAME. Not added in this migration...'
end
else begin
print 'Adding column COLUMNNAME to table TABLENAME...'
alter table TABLENAME
add COLUMNNAME int NOT NULL
CONSTRAINT CONSTRAINTNAME DEFAULT -1
end
go
Comments
The compare to script option writes the script as create procedure, etc.
I love your tools - keep up the good work!
It would be useful to know under what circumstances you would need to re-run the script?
Kind regards,
David Atkinson
Product Manager
Red Gate Software
Product Manager
Redgate Software
The reason we need this feature is, we generate the migration script from this tool SQL compare.
We have individual migration files for each version of our schema. In few migration files, the changes are repeated due to some reason (this can be avoided).
If we have this validation and creation feature will help us not to do manual massage after the script generation. This will save lot of our development timings.
-- Sarathi
David
Product Manager
Redgate Software
I hope you understand what I am trying to explain.
Basically the solution is, if the migration file has the repeated same statements (generally this situation will not happen, but if 2 or more modules are working in parallel and trying to create same object). This can be avoided if we have the “if exists†validation statement.