SQL Tutorial - TRUNCATE TABLE

SQL Tutorial - TRUNCATE TABLE

BeardedDev

6 лет назад

6,726 Просмотров

Another fantastic SQL Tutorial brought to you by BeardedDev.

SQL Tutorial - TRUNCATE TABLE - https://youtu.be/zJidbjOQlJM

If you want to to see a tutorial on how to use the DELETE statement in SQL Server, check out this video: https://youtu.be/VFNRtOQcyl0

If you want to see a tutorial on how to use the INSERT statement in SQL Server, check out this video: https://youtu.be/ar8scs8E5YI

You can see all videos on my channel focusing on Business Intelligence and Data Development by clicking the below link:
https://www.youtube.com/channel/UCWczzX6DyFV2KOYP_-CEZUA/videos

This tutorial will give you an overview of the TRUNCATE statement as well as discussing the differences compared to DELETE and show examples.

TRUNCATE TABLE removes all data from a table but keeps the table definition, DROP TABLE would completely remove the table.

TRUNCATE TABLE resets the current identity value and that is shown in an example in this video, we use IDENT_CURRENT statement to identify the current value then run the statement a second time after the TRUNCATE TABLE to see the difference.

TRUNCATE TABLE is also minimally logged, meaning only data pages that are removed are logged and we are unable to ROLLBACK. DELETE will log each row and can be rolled back.

We also show an example of the differences in performance between TRUNCATE and DELETE, when I run TRUNCATE it executes almost instantly but DELETE takes 46 seconds.

Don't forget to subscribe and hit the notification button to be made aware of when new videos are uploaded.

SQL Statements used in the video:

SELECT IDENT_CURRENT('dbo.CustomersSTG2') AS Current_Identity

TRUNCATE TABLE dbo.CustomersSTG2

INSERT INTO dbo.CustomersSTG2 (FullName, Age)
SELECT
FullName
, Age
FROM dbo.CustomersSTG

DELETE FROM dbo.CustomersSTG2

-- TRUNCATE SYNTAX
TRUNCATE TABLE [schema].[tablename]

Тэги:

#truncate_table #sql_drop_table #delete_table_sql #sql_truncate #truncate_command_in_sql #sql_clear_table #truncate_table_mysql #truncate_table_sql #delete_and_truncate #difference_between_delete_and_truncate #truncate_vs_delete #truncate_table_oracle #truncate_table_sql_server #postgressql_truncate #truncate_syntax #truncate_meaning_in_sql #truncate_statement_in_sql #tsql_truncate #truncate_example #truncate_tutorial #how_to_use_truncate_in_sql #truncate_command #truncate
Ссылки и html тэги не поддерживаются


Комментарии:

@Magswap
@Magswap - 18.07.2023 14:19

Thank you very much for this!

Ответить
@janeb7397
@janeb7397 - 19.02.2023 21:51

Great vid! Thank you

Ответить
@angelgonzales8238
@angelgonzales8238 - 16.05.2022 21:41

Thnak you

Ответить
@Dean.unicity
@Dean.unicity - 12.08.2021 13:43

Great video to see the difference. It's totally clear now

Ответить
@Gamma3
@Gamma3 - 11.04.2021 01:17

Gracias amigo, excelente canal. Me suscribo!

Ответить