-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.

3
  • I removed the incompatible atabase tags. Commented Oct 19, 2016 at 11:14
  • @a_horse_with_no_name MYSQL. Commented Oct 19, 2016 at 11:18
  • Your question is not very clear. Please add the SQL code (DDL) for the tables and the procedure you have at the moment. Also show some sample data for before and after your procedure runs (expected output). Commented Oct 19, 2016 at 11:29

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.