Problem with trigger

  • g5808599 (6/24/2015)


    If there is a new row with Sean - Steve. i must do these things:

    1) I must insert into table Friends the symmetric value (Sean - Steve) ----> And is not a problem

    2) I must check into table Relationship if there is a row with value (Sean - Steve).

    if not exists insert into Relationship value (Sean, Steve, 1) I insert 1 because i've got a direct path.

    if already exists i must check is GradeOfRelationship value if is = 0 or >1 then i ll set GradeOfRelationship = 1

    What if there is already a row with (Steve, Sean, 1)???

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • i don't update. It remains 1.

    This is the original exam that i translate

    The report contains Friend couples in SN. The report contains GradoOfRelationship, for a given pair of people, its GradeOfRelationship of friendship, which is the minimum number of steps to be taken in the graph of friendships to switch from the first to the second person. For example, if Marc is friends with John and Brad, John is a friend of Luc, Brad is a friend of Max and Max is a friend of Luc, the degree of friendship between Al and Luc is 2, because the journey Marc-> John- > Luc is shorter (the way Marc-> Brad-> Max-> Carl provides one more step). Two friends have direct GradeOfRelationship 1. Two people can not be reached from each other in the graph have degree 0.

    Design a system of triggers that:

    make sure that the relationship is symmetrical Friend (if A is a friend of B, B must also be a friend of A);

    Update for each pair of people in the database to the degree of friendship.

    Maybe now ll be more clear

  • g5808599 (6/24/2015)


    i don't update. It remains 1.

    This is the original exam that i translate

    The report Friend contienele couples diamici in SN. The report contains GradoAmicizia, to a pair of data PEOPLE, the Relative "degree" of friendship, That is the minimum number of steps to Perform in the graph of friendships to Switch From the first to the second person. For example, if John and 'friend of Marc and Brad, a friend of Marc and Luc, Brad And a friend of Max and Max and friend of Luc, the degree of friendship between John and Luc and' 2, as the journey John-> Marc-> Luc And What shorter (the camminoAl-> Brad-> Max-> Luc foresees a step in more). Two Friends Directed They grado1. Two PEOPLE unreachable Una other in the graph have degree 0.

    That design a trigger system that:

    Ensuring the report Friend Both symmetric (if A and B's friend, Also B devel Being a friend of A);

    Update for ANY pair of PEOPLE Present in the database of the respective degree of friendship.

    Maybe now ll be more clear

    I think a bunch of stuff here got lost in translation. It seems to be a mix of languages now. 😉

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • J Livingston SQL (6/24/2015)


    ve got this problem with this exercise

    maybe useful to see the original exam question....just a thought

    maybe not 😉

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • Sean Lange (6/24/2015)


    g5808599 (6/24/2015)


    i don't update. It remains 1.

    This is the original exam that i translate

    The report Friend contienele couples diamici in SN. The report contains GradoAmicizia, to a pair of data PEOPLE, the Relative "degree" of friendship, That is the minimum number of steps to Perform in the graph of friendships to Switch From the first to the second person. For example, if John and 'friend of Marc and Brad, a friend of Marc and Luc, Brad And a friend of Max and Max and friend of Luc, the degree of friendship between John and Luc and' 2, as the journey John-> Marc-> Luc And What shorter (the camminoAl-> Brad-> Max-> Luc foresees a step in more). Two Friends Directed They grado1. Two PEOPLE unreachable Una other in the graph have degree 0.

    That design a trigger system that:

    Ensuring the report Friend Both symmetric (if A and B's friend, Also B devel Being a friend of A);

    Update for ANY pair of PEOPLE Present in the database of the respective degree of friendship.

    Maybe now ll be more clear

    I think a bunch of stuff here got lost in translation. It seems to be a mix of languages now. 😉

    i just correct

  • g5808599 (6/24/2015)


    i don't update. It remains 1.

    This is the original exam that i translate

    The report contains Friend couples in SN. The report contains GradoOfRelationship, for a given pair of people, its GradeOfRelationship of friendship, which is the minimum number of steps to be taken in the graph of friendships to switch from the first to the second person. For example, if Marc is friends with John and Brad, John is a friend of Luc, Brad is a friend of Max and Max is a friend of Luc, the degree of friendship between Al and Luc is 2, because the journey Marc-> John- > Luc is shorter (the way Marc-> Brad-> Max-> Carl provides one more step). Two friends have direct GradeOfRelationship 1. Two people can not be reached from each other in the graph have degree 0.

    Design a system of triggers that:

    make sure that the relationship is symmetrical Friend (if A is a friend of B, B must also be a friend of A);

    Update for each pair of people in the database to the degree of friendship.

    Maybe now ll be more clear

    With this updated translation, things are more clear, and while the first task is relatively simple, the latter requires recursion, and getting a recursive CTE to perform well enough will be quite the challenge. Please read the following article by Adam Machanic and see if you can apply the advanced methods. I wouldn't make that attempt without knowing I had plenty of time available.

    http://sqlblog.com/blogs/adam_machanic/archive/2015/04/07/re-inventing-the-recursive-cte.aspx

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • infact for the first questions i've already found solution 😀

    I just read the arthicle, very interesting but also not so easy like i though in the first time that i saw the text of the exam :crying:

    I think that we can use something similar, as you can see in the main post i wrote a recursion statement with CTE but it didn't work.

Viewing 7 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic. Login to reply