create table cha(col1 int identity(1,1),col2 varchar(10))---基表 go insert into cha values('a') insert into cha values('b') insert into cha values('c') insert into cha values('d') insert into cha values('e') insert into cha values('f') insert into cha values('g') insert into cha values('h') go select * from cha() go create table tx(col int identity(1,1), chsum int)---验证表 go set identity_insert tx on insert into tx(col,chsum) select col1,binary_checksum(*) from cha go select *--- 查看验证表 from tx go ----更新基表,对第一行和第三行记录进行更新--- update cha set col2='a1' where col1=1 go update cha set col2='c1' where col1=3 go ----查看基表哪些行改变了--- SELECT col FROM tx WHERE EXISTS ( SELECT col1 FROM cha WHERE cha.col1 = tx.col AND BINARY_CHECKSUM(*) <> tx.chsum)
有序数据文件 bcp 实用工具和 BULKINSERT 语句分别接受 ORDER 提示和 ORDER 子句,它们使用户得以指定数据文件中的数据如何排序。尽管数据文件中的数据与表中的数据排序次序不必相同,但相同的排序可以提高大容量复制操作的性能。 表中数据的顺序由聚集索引确定。ORDER 提示或 ORDER 子句中列出的顺序和列必须匹配聚集索引中的各列,并且顺序相同,以便提高大容量复制操作的性能。 例如,若要将数据从 Authors.txt 数据文件大容量复制到 pubs 数据库的 authors2 表,并指定数据文件的 au_id 列以升序排序,请在命令提示符下执行以下命令: bcp pubs..authors2 in authors.txt -c -t, -Sservername -Usa -Ppassword -h "ORDER (au_id ASC)" 另外,也可以在 SQL 查询分析器这样的查询工具中使用 BULKINSERT 语句来大容量复制数据: BULKINSERT pubs..authors2 FROM'c:authors.txt' WITH ( DATAFILETYPE ='char', FIELDTERMINATOR =',', ORDER (au_id ASC) )