September 14, 2002 at 9:45 pm
Hello. I'm a beginner to SQL. I'm currently learning it in college. We had a discussion about primary keys/foreign keys, but I don't quite understand how to create foreign keys. From what I know, you create a primary key in each table..and a foreign keys to link them. I created tables like these:
Table1 columns: title1, pcmanuf, date
Table2 columns: employeeid, title1, hiredate
Table3 columns: orders, employeeid, takenby
i put primary keys on the title1(table1), employeeid(table2), and orders(table3) columns. but when it came to foreign keys, i couldn't create them. i think you link it this way:
employeeid will be the reference to pcmanuf, and orders will be the reference to takenby.
is this right or am i lost? thanks for any help.
September 15, 2002 at 5:35 am
Not sure, sounds close. A good way to see and learn is to use the diagrams built into Enterprise Manager. Add your three tables to the diagram, then you can drag a column from one table to the the other - you'll get a dialog allowing you to fine tune the relationship. Then instead of just saving the diagram (which actually applys the changes you're drawing to the tables) use the button to save the script so you can see what EM is doing. Try this a few times you'll get the hang of it. Once you understand the basics, try creating a self referencing table - employees is usually a good example, each employee row will have a managerid that is really an employeeid in the same table.
Andy
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply