本文以一个简单实例为大家介绍了sql中truncate和delete的区别,帮助大家理解,具体内容如下
<div class="jb51code">
<pre class="brush:sql;">
---创建表Table1
IF OBJECT_ID('Table1','U') IS NOT NULL
DROP TABLE Table1
GO
CREATE TABLE Table1
(ID INT NOT NULL,FOID INT NOT NULL)
GO
--插入测试数据
INSERT INTO Table1
VALUES(1,101),(2,102),(3,103),(4,104)
GO
---创建表Table2
IF OBJECT_ID('Table2','U') IS NOT NULL
DROP TABLE Table2
GO
CREATE TABLE Table2
(
FOID INT NOT NULL)
GO
--插入测试数据
INSERT INTO Table2 VALUES(101),(102),(103),(104)
GO
SELECT FROM Table1
GO
SELECT FROM Table2
GO