sql azure - SSIS - check if database and tables exist, if not - run sql to create -


i planning on importing data azure sql database using ssis package. know can oledb source , destination want check if database , tables exist , if not - create them. planning on using execute sql task create database , tables, how first check if exist?

so if database , tables exist, run data flow task transfer data, if not exist - run execute sql task create database , tables , run data flow task.

how can accomplish that?

  1. create ole db connection manager server , master database on it. apply connection manager next 2 steps.
  2. create 2 sql tasks in container. first sql task check see if database exists. can pass database name variable , apply in sql example shown below. "?" database name variable.

    if not exists(select * sys.sysdatabases name=?) -- create database

  3. then second sql task apply following in database , table name passed variables. but, in difference previous sql, can apply expression defining sql.

    "if object_id(n'" + <@databasename> + "dbo." + <@tablename> + ", n'u') null create table " + <@databasename> + "dbo." + <@tablename> + " ( field1 varchar(20) not null ,field2 tinyint not null );"


Comments