locked
Foreign Keys in Azure RRS feed

  • Question

  • Hello

    I have problem with Windows Azure SQL Database. I connected my application with the cloud database successfully. I made successfully inserts, deletes, updates. Now my problem is i have three tables for example: subjects, professors, subject_professor.

    Subjects = {id_subject}

    Professors = {id_professor}

    subject_professor = {id_subject, id_professor} - which are foreign keys of the two tables above

    In c#/xaml windows phone 8 i created the three tables but now when i want to add item in the subject_professor table i got an error. I tried to take the ID from one table and put it in variable but after Azure changed the primary key to be String instead of int i don't know anymore how to put in var.

    Here is another example:

    Subjects newSub = new Subjects();

    var ID = newSub.id; -----> here is the problem cos ID is no longer int 

    newSub.Name = "Mathematics" ----> thats working (the ID is created automatically when i create new object )

    await subs.InsertAsync(newSub);

    Professors newProf = new Professors();

    var ID2 = newProf.id

    newProf.Name = "Test";

    await pro.InsertAsync(newProf);

    subject_professor another = new subject(professor) ---> which professor teaches what subject

    another.id_subject = ID;

    another.id_professor = ID2;

    Here i got problem and it says that ID cant reference to null value.

    Please i need help with this problem Thank you.



     

     
    Saturday, November 30, 2013 12:03 AM

Answers

  • Hello,

    Firstly, the Primary keys and foreign keys constraints in Windows Azure SQL database is similar to primary database. So the primary key in SQL database can be int or string. Based on your description, it seems that you use Windows Azure Table storage rather than Windows Azure SQL Dabase.

    Unlike SQL Server or SQL database which are relational database, Windows Azure Table Storage stores structured data without schemas, it does not provide any way to represent relationships between the data or enforce relationships with foreign key constraints.  If you want to build relationships between tables, you can try to use schema-less properties of tables and structuring the data in the required format.

    If you have more question about Windows Azure Table Storage, you can post question in this forum

    Reference:Windows Azure Table Storage
    Windows Azure Table Storage and Windows Azure SQL Database - Compared and Contrasted

    Regards,
    Fanny Liu


    Fanny Liu
    TechNet Community Support

    • Proposed as answer by Fanny Liu Monday, December 9, 2013 1:24 AM
    • Marked as answer by Fanny Liu Wednesday, December 11, 2013 6:20 AM
    Tuesday, December 3, 2013 6:35 AM