which is best truncate or delete to remove all rows from table student_course?

ahmed salah 3,216 Reputation points
2022-04-27T17:43:39.927+00:00

I work on sql server 2017

i need to delete all rows from table student_course

but i don't know use

delete from student_course

or

truncate table student_course

table student_course

studentid pk

courseid pk

table student table

studentid pk

table courses

courseid pk


student_course table have relation with courses table and student table

so which command will be used to delete all rows from table student_course

truncate or delete ?

What I have tried:

delete from student_course

or

truncate table student_course

Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Naomi Nosonovsky 8,431 Reputation points
    2022-04-27T18:22:27.27+00:00

    If you want to delete all rows from student_course and there are no dependencies on that table in the database, the TRUNCATE TABLE student_course should be faster.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2022-04-27T19:34:39.947+00:00

    If you have an foreign key to the table, you must use delete, instead of truncate.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.