|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
inserting tables
Hi,
I'm trying to insert some tables into a postgres database, but i seem to be having some problems. I've inserted a table called advert, which is laid out as follows: advert_id - (PK) username mod_book_id (this links to the another table called module_books on the tables primary key called "id") asking_price condition date_added ive made the advert_id the primary key, but do i need to make the mod_book_id the foreign key? If I don't, will this cause problems when retrieving data? i'm doing this in postgress and have already inserted the table using the following: CREATE table advert (advert_id int(8), username varchar(20), mod_book_id int(8), asking_price int(6), conidition varchar(20), date_added TIMESTAMP, PRIMARY KEY(advert_id) ); i think I need to make the advert_id an autonumber, and i want the data_added filed to automatically be entered when someone places an advert. I'm doing this via linux and its command driven, im not sure how to make these above changes to my already existing tables. Can anyone help? thanks. lou |
|
#2
|
|||
|
|||
|
RE: inserting tables
I think the only reason to use foreign keys is to represent the structure of the database more intrinsically, so that you can see the relationships from the foreign keys. Also it stops you dropping tables in the wrong order, which is more of a pest than anything.
I don't think I could go back to working with foreign keys in databases, it really adds no value. Some say cascading deletes is nice, but I think that's just being lazy. Rather make your code exhibit all the behaviour, that way it is contained. I am no expert on this; I did Oracle a long time ago and recall I hated them very much. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > inserting tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|