I just got out of school with my AAS in computer programming and am still working on bettering my database skills. I've talked with a programmer where I work and he said that he 100% of the time creates his relationships through code instead of the GUI on either Access or SQL Server. How is this possible? I've never been taught how to create relationships through code - only through the GUI. I figure I might as well learn how to do it through code since I'll know everything that's going on then.
Sorry for such a novice questions.
Page 1 of 1
1 Replies - 446 Views - Last Post: 14 October 2011 - 06:34 AM
Replies To: How to create table relationships in code?
Re: How to create table relationships in code?
Posted 14 October 2011 - 06:34 AM
Take a look at adding constraints like Foreign Keys. You can use an ALTER TABLE query to modify an existing table, or you can include the constraints when you CREATE TABLE. There are a bunch of SQL Tutorials you can check out regarding this.
ALTER TABLE table_name ADD FOREIGN KEY(column) REFRENCES other_table(other_column); //OR CREATE TABLE table_name( col1, col2, col3, FOREIGN KEY (col3) REFERENCES other_table(other_column) );
Page 1 of 1