TRUNCATE TABLE

默认情况下,IDENTITY_INSER就是off
这种情况下,你写insert 语句时,identity栏位,不要写值,系统会自动帮你写入。

举例说明:
create table #aa(id int identity(1,1),dt datetime,pay int)
go
insert into #aa(dt,pay)values('2012-4-12',100) --不能向 id栏位写值,系统会自动写
go
insert into #aa(id,dt,pay)values(100,'2012-4-14',200) --如果像这样写了,就会报错
go

如果你需要写,可以把off改成on。
如:
set IDENTITY_INSERT #aa on
insert into #aa(id,dt,pay)values(100,'2012-4-14',200) --这样就不会报错了。
实际应用,应该不会要这样,一般设为 identity,就是要利用系统自动写入的功能,保证不重复。


TRUNCATE TABLE:

1.DELETE
 ・DML语言
 ・可以回退
 ・可以有条件的删除

     DELETE FROM 表名
   WHERE 条件

2.TRUNCATE TABLE
 ・DDL语言
 ・无法回退
 ・默认所有的表内容都删除
 ・删除速度比delete快。

   TRUNCATE TABLE 表名








USE SET IDENTITY_INSERT ON


set IDENTITY_INSERT t_menu on
insert into t_menu(menu_id,locale_id,area_id,menu_level,name,sequence,text,process)
select '14999',2052,0,'BASE','MAIN',0,'接收','RECEIPT'


猜你喜欢

转载自hkendless.iteye.com/blog/1895080