i have two tables with the following columns:

departments:
departmentID tinyint not null
department varchar( 30 ) not null

employees:
employeeID SMALLINT(5) not null 
departmentID tinyint not null
firstName varchar(30) not null
lastName varchar(30) not null

how do i create the two tables using SQL with a foreign key linking the two tables?

tbl1 is the name of the table with the PK you want to reference and ID will be the PK you want to reference.

myForeignKey int FOREIGN KEY REFERENCES tbl1(ID)

Do this when you creating the second table, if you the table already exists do it in an ALTER statement.

Alot of people might not like this site but it's help me alot in the past:

http://www.w3schools.com/sql/sql_foreignkey.asp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.