Results 1 to 15 of 15

Thread: SQL question.

  1. #1
    Join Date
    15th March 2004 - 13:00
    Bike
    Austrian and Italian
    Location
    Glenfield, Auckland
    Posts
    4,687

    SQL question.

    Hopefully there's an SQL guru out there that can help with this.

    Using SQL Server 2000, shifting a couple of tables from one db to another, receiving an error with a couple of the tables about Foreign Key constraints. The error tells me the row in the database and what field is the problem. I'd like to jump into query analyser to find out whats in the fields but what is the syntax to specify a particular row?

    I cant just open the whole database, we're talking a few million rows here (literally).

    Select * from table where ?????(row number) = 3345227.

    Help?

  2. #2
    Join Date
    4th July 2005 - 15:58
    Bike
    Apriliaaah!
    Location
    Auckland
    Posts
    1,609
    Our SQL guru left earlier on this morning sorry. My experience is limited, but have never tried to address a record by its row number so dont know if it is even possible. Can you get any other info on whats in the row and base your query on that?

    If you are still having probs on Monday I'll run it past our SQL consultant and see what he comes up with.

  3. #3
    Join Date
    15th March 2004 - 13:00
    Bike
    Austrian and Italian
    Location
    Glenfield, Auckland
    Posts
    4,687
    Unfortunately not. Just a rownumber, database, table and fieldname, but no values. Bugger.
    Cheers.

  4. #4
    Join Date
    4th July 2005 - 15:58
    Bike
    Apriliaaah!
    Location
    Auckland
    Posts
    1,609
    Just been trying to see if I can find a way for you, but none of our references seem to outline such a method. All the WHERE clauses I can find are based solely on the data within a given field, rather than something like what you are looking for.

    Google groups are coming up blank so far too.

  5. #5
    Join Date
    7th September 2004 - 16:18
    Bike
    mutterbumpkin
    Location
    UnderTheThumb
    Posts
    353

    ***

    Sql 200 has no "row" number concept when selecting. You must use a known column value in the where clause.

    Got the actual error message? i'd like to see it...

    Another option is to disable RI temporarily on the destination, copy the data then use a sql statement(s) to determine all rows that would fail RI like

    select [columns] from [table1] where not exists
    (select [foreign_key_column] from table2 where table1.[fk_key_column] = table2.[fk_column])

    note: stuff in [] is placeholders

    How are you shifting them? DTS? Transact Sql via "select into"? via enterprise managers object copy? ... may as well tansfer this to a PM - no use bothering the good people of KB with Sql stuff....

  6. #6
    Join Date
    15th March 2004 - 13:00
    Bike
    Austrian and Italian
    Location
    Glenfield, Auckland
    Posts
    4,687
    Tis in off topic anyway, its a thread now so may as well make the most of it!
    Using DTS (Tables and Data) to shift the info. The error messages are as follows (well, they're pretty much all the same, jsut different tables/fields).

    Its actually trying to shift historical session data from an Old Webmarshal database to a new one.

    "Error at Destination for Row number 2376219. Errors encountered so far in the this task: 1.
    The statement has been terminated.
    INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_DomainLog_SessionLog'. The conflict occured in database 'WebMarshal2', table 'SessionLog', column 'SessionLogId'."

    Just had an idea, I was shifting the SessionLog table at the same time, but it was processed after the above table. Maybe I need to shift that table first by itself then shift the others? (DomainLog, DomainFileLog, URL).

  7. #7
    Join Date
    26th February 2005 - 15:10
    Bike
    Ubrfarter V Klunkn,ffwabbit,Petal,phoebe
    Location
    In the cave of Adullam
    Posts
    13,624
    Quote Originally Posted by Devil
    ..
    Using DTS (Tables and Data) to shift the info. The error messages are as follows (well, they're pretty much all the same, jsut different tables/fields).

    Its actually trying to shift historical session data from an Old Webmarshal database to a new one.

    "Error at Destination for Row number 2376219. Errors encountered so far in the this task: 1.
    The statement has been terminated.
    INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_DomainLog_SessionLog'. The conflict occured in database 'WebMarshal2', table 'SessionLog', column 'SessionLogId'."
    ...
    Yes, you need to shift the Sessionlog table (the one with the primary key value) first. Otherwise the odds are that the tables are not copied in sync and the DomainLog copy tries to write a record that doesn't yet ahve a Sessionlog key. Or else disable the foreign key while copying and then restore it afterwards.
    Quote Originally Posted by skidmark
    This world has lost it's drive, everybody just wants to fit in the be the norm as it were.
    Quote Originally Posted by Phil Vincent
    The manufacturers go to a lot of trouble to find out what the average rider prefers, because the maker who guesses closest to the average preference gets the largest sales. But the average rider is mainly interested in silly (as opposed to useful) “goodies” to try to kid the public that he is riding a racer

  8. #8
    Join Date
    31st March 2003 - 13:09
    Bike
    CBR1000RR
    Location
    Koomeeeooo
    Posts
    5,559
    Blog Entries
    9
    A way around it might be to find the offending SessionLogId which is being duplicated (and should be unique by the look of the validation)

    Select SessionLogId, count(*)
    From SessionLog
    Group by SessionLogId having count(*) > 1

    From there you could export the rows, delete them from the db and/or re-enter them?

    Not sure if that's 100% MS SQL standard but it's what I learned (a few years ago)

    Or, once you know the SessionLogId with >1 entry, just select it (Select * from ... where SessionLogId = 'xxx') and look at the rows returned,

    Issue a targeted delete statement on the offiending ro (where SessionLogId = 'xxx' AND other_condition = 'unique value')

    MDU
    $2,000 cash if you find a buyer for my house, kumeuhouseforsale@straightshooters.co.nz for details

  9. #9
    Join Date
    15th March 2004 - 13:00
    Bike
    Austrian and Italian
    Location
    Glenfield, Auckland
    Posts
    4,687
    Good ideas people. Cheers. Takes a question like this to bring the geeks out of the woodwork muahaha!

  10. #10
    Join Date
    30th September 2004 - 20:08
    Bike
    Tojo and nothing. Damnit.
    Location
    Brighton, UK
    Posts
    2,338
    Quote Originally Posted by Devil
    Select * from table where ?????(row number) = 3345227.
    Does M$SQL have a way of doing

    'SELECT * FROM blahTable OFFSET 7 LIMIT 1 ;'

    Which would suffice.

  11. #11
    Join Date
    8th July 2005 - 12:33
    Bike
    1997 Suzuki TL1000 S, 1999 Ducati 996S ?
    Location
    Wellington
    Posts
    87
    Can only recommend shifting the parent tables first. Otherwise the lack of a valid FK, which the child is reliant on will make your app drop its guts.

    "I'd like to jump into query analyser to find out whats in the fields but what is the syntax to specify a particular row?"

    Don't know the syntaxt for SQL Server 2000 but you could try something along the lines of:

    SELECT * FROM (SELECT * FROM [table] ORDER BY .... ) WHERE ROWNUM = [rownumber];
    If it ain't a V twin, it ain't worth shit.

  12. #12
    Join Date
    7th September 2004 - 16:18
    Bike
    mutterbumpkin
    Location
    UnderTheThumb
    Posts
    353

    ***

    Quote Originally Posted by limbimtimwim
    Does M$SQL have a way of doing

    'SELECT * FROM blahTable OFFSET 7 LIMIT 1 ;'

    Which would suffice.
    No, it might work in PostGre / MySql but not here in MS land...

  13. #13
    Join Date
    31st March 2003 - 13:09
    Bike
    CBR1000RR
    Location
    Koomeeeooo
    Posts
    5,559
    Blog Entries
    9
    Quote Originally Posted by Devil
    Good ideas people. Cheers. Takes a question like this to bring the geeks out of the woodwork muahaha!
    I resent that - I'm in SALES!.. hang on - that's worse...
    $2,000 cash if you find a buyer for my house, kumeuhouseforsale@straightshooters.co.nz for details

  14. #14
    Join Date
    15th March 2004 - 13:00
    Bike
    Austrian and Italian
    Location
    Glenfield, Auckland
    Posts
    4,687
    Quote Originally Posted by ManDownUnder
    I resent that - I'm in SALES!.. hang on - that's worse...
    Closet geek?

  15. #15
    Join Date
    7th November 2004 - 11:00
    Bike
    Aquired by locals
    Location
    Groote Eylandt
    Posts
    6,606
    Im hiding in the corner. SQL scares me
    To every man upon this earth
    Death cometh sooner or late
    And how can a man die better
    Than facing fearful odds
    For the ashes of his fathers
    And the temples of his Gods

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •