Created
June 16, 2017 10:35
-
-
Save aleksb86/6c9cea3e6c67265c352e78b79ed09faf to your computer and use it in GitHub Desktop.
Script for adding columns to any table (or other than ALTER mass executions).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Скрипт для добавления столбцов | |
--в таблицу. IN - список схем и таблиц в строковом виде. | |
use DWH_ODS_dev | |
GO | |
-------------------- | |
declare @t table (sch varchar(50), tabname varchar(50)) | |
declare @sch varchar(50) = '' | |
declare @tabname varchar(50) = '' | |
insert into @t values | |
('Salesforce', 'RecordType'), | |
('Salesforce', 'Land__c'), | |
('Salesforce', 'Account'), | |
('Salesforce', 'Storage__c'), | |
('Salesforce', 'Lead'), | |
('Salesforce', 'CurrencyCourse__c'), | |
('Salesforce', 'ReferenceBook__c'), | |
('Salesforce', 'FarmUnit__c'), | |
('Salesforce', 'EncumbranceData__c'), | |
('GIS', 'agrofields'), | |
('GIS', 'agrofields_infestations'), | |
('GIS', 'agrofields_plan'), | |
('GIS', 'agrofields_plans_approved'), | |
('GIS', 'agrolots'), | |
('GIS', 'farms_plan'), | |
('GIS', 'russia_adm3'), | |
('GIS', 'russia_adm4'), | |
('GIS', 'farms'), | |
('GIS', 'holdings'), | |
('GIS', 'staff'), | |
('GIS', 'lands_mult'), | |
('GIS', 'agrofields_usage_types'), | |
('GIS', 'boolean'), | |
('GIS', 'crop_rotation_groups'), | |
('GIS', 'crop_rotation_types'), | |
('GIS', 'seasons'), | |
('GIS', 'seeds_ownership_types'), | |
('GIS', 'seeds_types'), | |
('GIS', 'suitability'), | |
('GIS', 'techno_companies'), | |
('GIS', 'techno_intensities'), | |
('GIS', 'tmc_seeds'), | |
('OpenProject', 'wp_lavel_acess'), | |
('OpenProject', 'wp_org'), | |
('OpenProject', 'wp_podr'), | |
('OpenProject', 'wp_position'), | |
('OpenProject', 'wp_rost_assesment'), | |
('OpenProject', 'wp_rost_spr_assesment'), | |
('OpenProject', 'wp_rost_spr_purpose'), | |
('OpenProject', 'wp_rost_time_period'), | |
('OpenProject', 'wp_spr_cmp_levels'), | |
('OpenProject', 'wp_users') | |
declare cur cursor | |
local static read_only forward_only | |
for select distinct sch, tabname from @t | |
open cur | |
fetch next from cur into @sch, @tabname | |
while @@FETCH_STATUS = 0 | |
begin | |
print @sch + '.' + @tabname | |
exec('alter table ' + @sch + '.' + @tabname + | |
' add [Valid_StartDate] [DATETIME] NULL, [Valid_EndDate] [DATETIME] NULL') | |
fetch next from cur into @sch, @tabname | |
end | |
close cur | |
deallocate cur | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment