 	group by       "exa_table_schema", "exa_table_name"
 	order by       "exa_table_schema","exa_table_name"
 
-), vv_imports as (
+), vv_foreign_keys as (
+
+select 'ALTER TABLE "' || "exa_table_schema" || '"."' || "exa_table_name" ||
+ '" ADD FOREIGN KEY (' || '"'||  "exa_foreign_key_column" || '") REFERENCES "' || "exa_referenced_table_schema" || '"."' || "exa_referenced_table_name" || '" DISABLE ;' as sql_text
+from vv_foreign_keys_raw   
+order by "exa_table_schema","exa_table_name"
+
+)
+, vv_imports as (
 	select 'import into "' || "exa_table_schema" || '"."' || "exa_table_name" || '" from jdbc at ]]..CONNECTION_NAME..[[ statement ''select ' || group_concat( 
 	case 
 	when "data_type" = 'DA' then "column_name_delimited"

table_name like '']]..TABLE_FILTER..[['' 
'
) as primarykeylist
),
vv_create_schemas as(
	SELECT 'create schema "' || "exa_table_schema" || '";' as sql_text 

select * from vv_imports
UNION ALL
select * from vv_primary_keys
UNION ALL
select * from vv_foreign_keys
]],{})

return(res)
