Created
December 30, 2013 13:59
-
-
Save JorgenEvens/8182377 to your computer and use it in GitHub Desktop.
Copy tables from a shared schema to your local schema in db2
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
#!/bin/sh | |
ME=`whoami` | |
SRC="project" | |
if [ -z "$1" ]; then | |
TABLES="table1 table2" | |
else | |
TABLES=$@ | |
fi | |
copy() { | |
echo db2 "DROP TABLE ${ME}.${1}" 2> /dev/null | |
echo db2 "CREATE TABLE ${ME}.${1} LIKE ${SRC}.${1}" | |
echo db2 "ALTER TABLE ${ME}.${1} ACTIVATE NOT LOGGED INITIALLY" | |
echo db2 "INSERT INTO ${ME}.${1} ( SELECT * FROM ${SRC}.${1} )" | |
echo db2 "commit" | |
db2 "DROP TABLE ${ME}.${1}" 2> /dev/null | |
db2 "CREATE TABLE ${ME}.${1} LIKE ${SRC}.${1}" | |
db2 +c "ALTER TABLE ${ME}.${1} ACTIVATE NOT LOGGED INITIALLY" | |
db2 +c "INSERT INTO ${ME}.${1} SELECT * FROM ${SRC}.${1}" | |
db2 commit | |
} | |
db2 "connect to dbarch" | |
for table in $TABLES; do | |
copy "$table" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment