sqlserver 实现分页查询
select top ("+pageSize+") word from(select distinct(d_word)as word,row_number() over(order by id asc) as rownumber from dbo.zdbz_dict_all) as tb where rownumber>("+(i*pageSize)+")
将查询出来的数据导入到另外一个表中
select distinct(d_word) as word from dbo.zdbz_dict_all
创建表
mysql中的去重语句
)
sqlserver中查询字符串中含有%
select * from dbo.test_cs where word like '%%c%%' escape 'c'
select * from dbo.zdbz_dict_all where t_word like '%[%]%'
表示字符串中含有%就行
select * from dbo.test_cs where word like '%c%' escape 'c'
查询的结果为所有以%结尾的数据
select * from dbo.test_cs where word like 'e%%' escape 'e'
查询的结果为所有以%开始的数据
sql语句实现数据库中的两个表数据之间的更新
update dbo.zdbz_dict_all set origin=b.word from dbo.zdbz_dict_all as a
,dbo.origin as b where a.id=b.uri
基于数据库表建立索引
CREATE NONCLUSTERED INDEX IX_origin --创建一个非聚集索引
ON dbo.zdbz_dict_all(origin) --为dbo.zdbz_dict_all表的origin字段创建索引
WITH FILLFACTOR = 30 --填充因子为30%
如果将set statistics io 设置为on,则在执行SQL语句时将会显示磁盘活动的统计信息。如果将set statistics
io设置为off,则不显示统计信息。
set statistics io on
select * from
stuinfo--执行语句
set statistics
io off
基于SQLServer性能测试
create table table1
(
ID int identity(1,1),
UserID int,
OtherCol1 varchar(300),
OtherCol2 varchar(300)
)
create clustered index index_id on table1(id)
--清理一下表
truncate table table1
declare @i int
set @i=1
while (@i<2000000)
begin
insert into table1 values(substring(cast( RAND() as varchar),3,3),CAST(@i as varchar),CAST(@i as varchar));
set @i=@i+1
end
select count(1)from dbo.table1
select GETDATE()
select * from table1 where UserID='666'
create index index_userid on table1(userid)
select GETDATE()
drop index index_userid on table1