【学习点点滴滴】 在学习SQL 时,很多人都会与identity 打交道。当然我也才刚刚学习到它。这里我把我所理解的identity写出来。记录
一下。因为鄙人记心不太好。想以这种方式来加深理解与记忆。对identity的理解全拜CSDN的兄弟所赐。在此谢了哈!!
在理解之前我们先建两个表 create table [ta]([a] char,[b] char);create table [tb]([c] char)
要实现连个表的合并。但两表都没有主键。为此我们要用到 就很容易做到。 identity(int ,1,1) 可自动实现编号。
select * ,id= identity (int ,1,1) into ta1 from ta //
select * , id= identity (int ,1,1) into tb1 from tb//
这样我们就ta,tb的各列值复制到表ta1,tb1中,并增加了id列。
这样我们就很容易实现 两表的合并。
【 identity(int,i,j)实现ID自增, 从i 开始,每次以j 增长。 】
【select * into table1 from table2 // 执行此SQL语句 :将table2 的值全复制到table1 中。】