Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2011
    Posts
    9

    Unanswered: How Create tables with Primary Key and show Relationships

    Hi,

    I am coming from microsoft access background, intermediate, and I was totally bowled over by the other threads that are similar to mine.

    I definitely would need a more beginners response to my question, that is, if it is reasonable to ask such a thing.

    I would like to duplicate a database I just setup in access but now I oould like to do it in Postgresql and I have the following questions:

    What is the command I give to create a table with the following structure:
    tblClients with ClientID as the primary key and then the usual fields of LastName, FirstName and MI etc.
    tblClientLines with a composite primary key of ContractID and ClientID since it has a 1 to many relationship with tblClients and tblContracts.
    tblContracts with ContractID as the primary key and AuthCode etc as the other fields.

    Thank-you for your time and patience, any pointers or advice would be appreciated.

    tom.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    First: using a prefix of tbl is generally regarded strange outside the Microsoft World.

    To create the tables, just run the approriate CREATE TABLE statements. The syntax including a description of the available data types are explained in detail in the manual:
    http://www.postgresql.org/docs/curre...eatetable.html

    There is also a tutorial in the manual that gives an introduction on how to create tables:
    http://www.postgresql.org/docs/9.1/s...ial-table.html

    To build up "relationships" you have to define foreign keys. In the manual's tutorial section is a chapter about them:
    http://www.postgresql.org/docs/9.1/s...torial-fk.html

    A complete description is available in the chapter about data definition:
    http://www.postgresql.org/docs/9.1/s...CONSTRAINTS-FK

    I hope these links will get you started.

    I highly recommend you read the complete tutorial in the PostgreSQL manual. Not only to learn about PostgreSQL but also to learn about the building blocks of the SQL language.

    If you have any specific problems, please post the statements you are having problems with including the exact error messages.

    Please format any code using [code] tags. Details about how to do that can be found here:
    http://www.dbforums.com/misc.php?do=bbcode

  3. #3
    Join Date
    Oct 2011
    Posts
    9
    Thanks shammat....lots to read and learn from.

    tom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •