Jump to content

Archived

This topic is now archived and is closed to further replies.

yana

How to create a database and table?

Recommended Posts

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

Any code sample would be great!

Share this post


Link to post
Share on other sites
Dunno if this one's been answered .. how long has it been around?  Anyway, I did this in an *.sql file..

[i]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
);[/i]
.. etc. 

I then connect to the database and do ..

[i]\i <path_to_*.sql_file>[/i]

HTH.

Share this post


Link to post
Share on other sites
To create databases in postgres, you can use the createdb command:

[code]postgres $ createdb --help[/code]

for the syntax and options.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.