sqlserver设置主键自增
- ALTER TABLE dbo.TestTable DROP COLUMN Id
- ALTER TABLE dbo.TestTable ADD Id BIGINT IDENTITY ( 1, 1 ) NOT NULL
- ALTER TABLE dbo.TestTable ADD CONSTRAINT prim_Id PRIMARY KEY ( Id )
分页
- offset fetch next方式(SQL2012以上的版本才支持 )
- order by userid offset (页数-1)乘每页条数 rows fetch next 每页条数 rows only
数据存在更新,不存在插入
- if not exists (select 1 from t where id = 1)
- insert into t(id, update_time) values(1, getdate())
- else
- update t set update_time = getdate() where id = 1
持续更新...