uploading sql ddl file to postgresql database -


i relatively new working on databases. created sql file , want upload ddl (data definition language) file postgresql server. server runs on ubuntu 12.04.

create database *;  --create tables create table user(     user_id      varchar(36)    not null,     username     varchar(36)    not null,     user_type    varchar(36)    not null,     name         varchar(36)    not null,     email        varchar(36)    not null,     picture      varchar(36)    not null );  create table product(     product_id           varchar(36)    not null,     product_name         varchar(36)    not null,     product_type         varchar(36)    not null,     product_price        varchar(36)    not null,     product_available    varchar(36)    not null );  create table transaction(     transaction_id    varchar(36)    not null,     user_id           varchar(36)    not null,     product_id        varchar(36)    not null );  create table inventory(     product_id           varchar(36)    not null,     product_name         varchar(36)    not null,     product_available    varchar(36)    not null ); 

i not asking how fix file. asking how can upload file postgresql server. advance help.

running script

to run ddl in form of sql script, should use psql, same command use connect server interactively.

psql -h the.server.hostname -f my_script.sql the_database 

i recommend using on_error_stop=1 , -1, runs ddl in single transaction , aborts on error.

psql -v on_error_stop=1 -1 -h the.server.hostname -f my_script.sql the_database 

creating db

you can't create database start creating tables. must connect other db run create database , if you've connected db, that's tables created.

you can put psql command \c databasename in after create database, it'll create db switch it. it's bad idea: if create fails, script merrily keep on creating tables in wrong db unless use on_error_stop. can't use -1 (run in single transaction) if create , switch new db.

instead, manually create database first, or separate script. way can run ddl script sensibly.

the ddl

your schema needs work.

no primary keys.

no foreign keys.

use of varchar(36) everywhere, it's wildly inappropriate names , email addresses. use unbounded text type, or varchar no length (they're same thing in postgresql anyway) if don't have need constrain length of field specific reason.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -