belle’s sql musings

Generating Random Data for SQL Server and MySQL

Posted in DBA Toolbox / T-SQL Scripts, MySQL, T-SQL Tips and Tricks by belle on October 5, 2008

SQL Server – uses NEWID() in ORDER BY

   1: -- using the AdventureWorks Database
   2: SELECT
   3:     TOP 10
   4:     DepartmentID,
   5:     [Name]
   6: FROM
   7:     HumanResources.Department
   8: ORDER BY
   9:     NEWID()
  10:

MySQL – uses RAND() in ORDER BY

   1: SELECT
   2:   `Code`,
   3:   `Name`
   4: FROM
   5:   `Country`
   6: ORDER BY
   7:   RAND()
   8: LIMIT 10;
Advertisements
Tagged with:

One Response

Subscribe to comments with RSS.

  1. Random in SQL - SQL For Programmers said, on November 4, 2008 at 4:48 am

    […] Generating Random Data for SQL Server and MySQL – SQL Server – uses NEWID() in ORDER BY. 1: — using the AdventureWorks Database 2: SELECT 3: TOP 10 4: DepartmentID, 5: [Name] 6: FROM 7: HumanResources.Department 8: ORDER BY 9: NEWID() 10:. MySQL – uses RAND() in ORDER BY. 1: SELECT  Other post in SQL For ProgrammersSQL For Developers – 9 Reasons to bother – August 13th, 2008SQL for Programmers – CREATE/DROP Database – August 20th, 2008SQL For Programmers – CREATE TABLE – August 22nd, 2008SQL For Programmers – ALTERing the TABLE – September 1st, 2008SQL For Programmers – Finding a String – September 3rd, 2008SQL For Programmers – Finding IN a List – September 8th, 2008SQL For Programmers – Stored Procedures (Better than LINQ) – September 10th, 2008SQL For Programmers – Stored Procedure Basics – September 16th, 2008Basic SQL Commands – SQL For Programmers – September 18th, 2008SQL IF/WHILE Blocks – SQL For Programmers – September 30th, 2008SQL WHILE – SQL For Programmers – October 2nd, 2008Temporary Tables – SQL For Programmers – October 7th, 2008SQL CURSOR – SQL For Programmers – October 13th, 2008SQL CURSOR Performance – SQL For Programmers – October 22nd, 2008Random in SQL – SQL For Programmers – November 4th, 2008If you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!Related PostSQL WHILE – SQL For ProgrammersBasic SQL Commands – SQL For ProgrammersSQL For Programmers – Stored Procedure Basics Bookmark to: Hide Sites Tags: ms-sql, random, sql, tsql […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: