Search
 
SCRIPT & CODE EXAMPLE
 

SQL

ms sql truncate table vs delete

-- Quick, no possible rollback
TRUNCATE TABLE my_table;
-- With possible rollback
DELETE FROM my_table;
COMMIT;  -- or ROLLBACK;
Comment

delete vs truncate sql server

DELETE:
1.Delete command is used to delete a row in a table.
2.You can rollback data after using delete statement.
3.It is a DML command.
4.It is slower than truncate statement.

-- DELETE Syntax 
DELETE FROM table_name WHERE condition;

TRUNCATE:
1.Truncate is used to delete all the rows from a table
2.You cannot rollback data.
3.It is a DDL command.
4.It is faster.

-- TRUNCATE Syntax 
TRUNCATE TABLE table_name;
Comment

truncate delete and drop in sql

DELETE -
-DML COMMAND
-Delete Rows from the table one by one
-We can use where clause with Delete to delete single row
-Delete is slower than truncate
-ROLLBACK is possible with DELETE

DROP-
-DDL COMMAND
-Delete the entire structure or schema
-We can't use where clause with drop
-Drop is slower than DELETE & TRUNCATE
-ROLLBACK IS NOT POSSIBLE WITH DROP

TRUNCATE-
-DDL COMMAND
-Truncate deletes rows at a one goal
-We can't use where clause with Truncate
-Truncate faster than both DELETE & DROP
-Rollback is not possible with Truncate
Comment

SQL Delete and Truncate Rows

DELETE FROM Customers
WHERE customer_id = 5;
Comment

PREVIOUS NEXT
Code Example
Sql :: sql select whole row max column 
Sql :: decimal() mysql 
Sql :: list foreign key oracle 
Sql :: mysql if statement in where clause 
Sql :: sql server datetime 
Sql :: split string and get first and last element in sql server 
Sql :: mariadb create index if not exists 
Sql :: mysql mediumtext 
Sql :: sql insert into 
Sql :: sql to c# model 
Sql :: how to use query in nosql 
Sql :: SQL Query to delete all the tables in a database 
Sql :: how to update values in sql 
Sql :: sql 2 way of select unique 
Sql :: primary key sql 
Sql :: pgadmin postgres ERROR: database is being accessed by other users 
Sql :: oracle sql developer 
Sql :: sql table alias join 
Sql :: change sql global mode 
Sql :: mysql select database 
Sql :: find most frequent word in sql server 
Sql :: case construct in where clause 
Sql :: sql order of execution 
Sql :: getting customers with no orders sql 
Sql :: Syntax error or access violation: 1075 Incorrect table def inition; there can be only one auto column and it must be defined as a key 
Sql :: pl sql if boolean 
Sql :: import mysql command line 
Sql :: drop tables from local database postgres pgadmin 
Sql :: query to get all primary keys and foreign key 
Sql :: grab part of a string sql 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =