SQL Server Performance

Random Record Selection

Discussion in 'Contribute Your SQL Server Scripts' started by Madhivanan, Feb 7, 2005.

  1. Madhivanan Moderator


    This will randomly select records from the table

    Select * from Table Order by newid()

    Madhivanan
  2. rockmoose New Member

    Theoretically this is random as well:<br />Select * from Table<br /><br />However it will ususally give the same "random" result every time [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]
  3. Madhivanan Moderator

    <blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by rockmoose</i><br /><br />Theoretically this is random as well:<br />Select * from Table<br /><br />However it will ususally give the same "random" result every time [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />rockmoose, nice to see you here [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br /><br /><br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
  4. Argyle New Member

    Note that newid() is not really random on NT4 since it use a part of the MAC address for key generation or something. You will end up with same result most of the time. It might have been fixed in one of the later servie packs. But in theory noone should be using NT anymore [<img src='/community/emoticons/emotion-2.gif' alt=':D' />]
  5. Setareh New Member

    how to use execute to insert in the table
  6. FrankKalis Moderator

    Is your question related to NEWID()?
    Or are you looking for something like this?


    CREATE TABLE cmdshell (line VARCHAR(260))
    GO
    INSERT INTO cmdshell EXEC master.dbo.xp_cmdshell 'dir c: /B'
    SELECT
    *
    FROM
    cmdshell
    DROP TABLE cmdshell


    --
    Frank Kalis
    Microsoft SQL Server MVP
    http://www.insidesql.de
    Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)
  7. Madhivanan Moderator

    &gt;&gt;how to use execute to insert in the table<br /><br />It is always better to start a new topic than asking in other topic as your question does not seem to be related with this topic [<img src='/community/emoticons/emotion-1.gif' alt=':)' />]<br /><br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
  8. Ray D New Member

    May be
    select * from sysobjects order by checksum(newid()) ?

    WBR, Vlad A. Scherbinin

Share This Page