1 Replies - 837 Views - Last Post: 14 October 2011 - 06:34 AM Rate Topic: -----

#1 Criel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 146
  • Joined: 11-March 11

How to create table relationships in code?

Posted 13 October 2011 - 01:53 PM


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. :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to create table relationships in code?

#2 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12297
  • View blog
  • Posts: 45,399
  • Joined: 27-December 08

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);

CREATE TABLE table_name(
    FOREIGN KEY (col3) REFERENCES other_table(other_column)

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1