1 Replies - 492 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: 127
  • Joined: 11-March 11

How to create table relationships in code?

Posted 13 October 2011 - 01:53 PM

Hello,

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 online

  • Self-Trained Economist
  • member icon




Reputation: 10390
  • View blog
  • Posts: 38,451
  • 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);

//OR
CREATE TABLE table_name(
    col1, 
    col2, 
    col3, 
    FOREIGN KEY (col3) REFERENCES other_table(other_column)
);


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1