If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > How Create tables with Primary Key and show Relationships

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-26-11, 09:31
hlogoma hlogoma is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
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.
Reply With Quote
  #2 (permalink)  
Old 10-26-11, 10:08
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
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
Reply With Quote
  #3 (permalink)  
Old 10-26-11, 12:06
hlogoma hlogoma is offline
Registered User
 
Join Date: Oct 2011
Posts: 9
Thanks shammat....lots to read and learn from.

tom.
Reply With Quote
Reply

Tags
primarykey, tables

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On