How to delete rows from relational database So I have database with two tables. and they have foreign key relation between them. I want to do some testing but the tables are so big. I want to delete most of the data in these tables and just keep around 500 rows in the first table and the related rows in the second table so testing will be faster. How can I do that?

Database structure:
One simple way to do this is to extract the rows from those tables into temporary tables then truncate the source tables.

Example:

-- Load the top 500 UUT_RESULT records into a temp table
SELECT TOP (500) *
INTO #UUT_RESULT_TEMP
FROM UUT_RESULT
ORDER BY ID

-- Load the related STEP_RESULT records into a separate temp table
SELECT *
INTO #STEP_RESULT_TEMP
FROM STEP_RESULT
WHERE UUT_RESULT IN (SELECT TOP (500) FROM UUT_RESULT ORDER BY ID)

-- Remove the record
TRUNCATE TABLE STEP_RESULT
TRUNCATE TABLE UUT_RESULT

-- Load the records back in
INSERT INTO UUT_RESULT
SELECT * FROM #UUT_RESULT_TEMP

INSERT INTO STEP_RESULT
SELECT * FROM #STEP_RESULT_TEMP


Using TRUNCATE will help speed things up as this is a minimally logged operation.