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

    Unanswered: How Create tables with Primary Key and show Relationships


    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.


  2. #2
    Join Date
    Nov 2003
    Provided Answers: 23
    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:

    There is also a tutorial in the manual that gives an introduction on how to create tables:

    To build up "relationships" you have to define foreign keys. In the manual's tutorial section is a chapter about them:

    A complete description is available in the chapter about data definition:

    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:

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


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