-1

I am creating a make booking stored procedure.

In a Tutor table I have already added tutor records.

The TutorId is referenced in the Booking table by a foreign key constraint.

After manual input from visual studio for generic booking questions, I would like a random TutorId to be assigned with this BookingId.

Tony
  • 9,672
  • 3
  • 47
  • 75

1 Answers1

0
SELECT TOP 1 TutorId FROM Tutor ORDER BY NEWID()

This will return you a random record from your Tutor table.

A NEWID() is generated for each row and the table is then sorted by it. The first record is returned (i.e. the record with the "lowest" GUID).

Source: Random record from a database table

Community
  • 1
  • 1
Jens
  • 3,249
  • 2
  • 25
  • 42