SQL常用功能

SQL筛选出相同记录

选出相同记录的SQL语句是:
select * from tableName where id in (
select id from tableName group by id having count(*) > 1)

删除相同记录的SQL语句是:
delete from tableName where id in (
select id from tableName group by id having count(*) > 1)
例如:
select * from book where isbn in (
select isbn from book group by isbn having count(*) > 1)

MSSQL ID自动从1开始
DBCC   CHECKIDENT   (表名,   RESEED,   0)  >>MSSQL ID自动从1开始 或者 truncate   table   tablename

把存储过程记录集新增到另一表 INSERT INTO EXEC
truncate   table   [tablename] 清空表,ID自动从1开始,
 INSERT INTO [tablename]
 EXEC [dbo].[spname]
   @parameters = 0

posted @ 2008-07-13 10:39  alex hu  阅读(275)  评论(0编辑  收藏  举报