sql 语句
扫描二维码
随时随地手机看文章
Question 1 自增列问题
当设置有自增列时,使用delete 删除不掉自增列已占用编号,需要使用
trucate tabletablename 语句
可以完全删除
重置表的自增字段,保留数据
DBCC CHECKIDENT(tablename,reseed,0)
设置允许显式插入自增列
SETIDENTITY_INSERT tablename ON
当然插入完毕记得要设置不允许显式插入自增列
SETIDENTITY_INSERT tablename Off
另外对于带有自增列的表进行插入时,自增列不能插入,它会自动安编号插入。
使用
insert into tablename (列名,列名.... )select 列名,列名......from othertablename
可以进行表间的数据导入
Question 2 null 值 问题
当要查询为null 值时 发现使用 where columnname is null 或者 where columnname =null 无用
查询不到 ,于是使用了另一种方法
where isnull(columnname,'')=''
该语句的作用是 使用isnull函数 将列值 为 null的替换为’‘然后查找列值 为 ’‘的值
isnull(columnname,替换值)