Click here to Skip to main content
15,868,128 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 27-Apr-22 7:57am
Comments
[no name] 27-Apr-22 12:20pm    
Truncate is faster.
ahmed_sa 27-Apr-22 12:22pm    
are there are any issue if i use delete

1 solution

You can use either DELETE or TRUNCATE command to server the purpose.
SQL
DELETE FROM student_course
OR
TRUNCATE TABLE student_course
DELETE is use when we want to apply WHERE clause. TRUNCATE is faster and we cannot undu deleted records but in delete we can revert back.
Further, you can read the the difference between DELETE and TRUNCATE:
https://www.sqlshack.com/difference-between-sql-truncate-and-sql-delete-statements-in-sql-server/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900