Jump to content


Photo

How to create a database and table?


  • Please log in to reply
2 replies to this topic

#1 yana

yana
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts
  • LocationToronto, Canada

Posted 02 August 2006 - 02:56 PM

Is there a similar way to create a database and table in PostgreSQL as is in MySQL???

Any code sample would be great!
Yana

#2 jsmith67te

jsmith67te
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 November 2006 - 02:31 AM

Dunno if this one's been answered .. how long has it been around?  Anyway, I did this in an *.sql file..

CREATE SEQUENCE user_ids
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;

--
-- Table "users"
-- Name: users; Type: TABLE; Schema: public; Owner: cdi
--

CREATE TABLE users (
    user_id integer DEFAULT nextval('user_ids'::text) PRIMARY KEY,
    username character varying(128) DEFAULT ''::character varying NOT NULL,
    mail_host character varying(128) DEFAULT ''::character varying NOT NULL,
    alias character varying(128) DEFAULT ''::character varying NOT NULL,
    created timestamp with time zone DEFAULT now() NOT NULL,
    last_login timestamp with time zone DEFAULT now() NOT NULL,
    "language" character varying(5) DEFAULT 'fr'::character varying NOT NULL,
    preferences text DEFAULT ''::text NOT NULL
);

.. etc. 

I then connect to the database and do ..

\i <path_to_*.sql_file>

HTH.

#3 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 14 November 2006 - 05:07 AM

To create databases in postgres, you can use the createdb command:

postgres $ createdb --help

for the syntax and options.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users