Donets

TSQL笔记1

 

  1. truncate table <tablename>
    运行后 表中的 标识列会 初始化 delete 没这功能
  2. declare @dayid int
    set @dayid=datepart(y,getdate())
    declare @year int
    set @year=datepart(year,getdate())
    insert into top_days (musicid,hits,year,dayid,sortid) 
    select top(100000) id,hits,@year,@dayid,ROW_NUMBER() over(order by hits descfrom dlist 
    表 top_days中 year,dayid 都是有默认值的 可批量插入的时候 用默认值速度太慢了 这样写后 速度是原来的30倍以上 (5万行数据操作)
  3. select top(100000) id,hits,ROW_NUMBER() over(order by hits descfrom dlist 
    TSQL 给查寻出的结果一个编号 如果over里的 排序的 语句的排序一样 可以不用 select中的排序
  4. =====本文原创地址:http://Donets.cnblogs.com  ===========
  5. 2中的 top_days表 存在 year,dayid,hits,musicid索引 批量插入前选 把索引给删掉 插入后再键索引(速度会提10倍以上)
  6. 如果数据库经常插入大量数据的话 自动增长 最好设置大一点 否则 select into这样批量插入时速度会很慢
  7. 应用程序或 SP能控制的列值 尽量不要用 Check(呵呵 速度&性能问题)

分类:

技术点:

相关文章:

  • 2022-01-18
  • 2022-02-14
  • 2022-03-07
  • 2021-08-05
  • 2022-01-18
  • 2021-06-07
猜你喜欢
  • 2021-07-22
  • 2021-09-27
  • 2021-09-29
  • 2021-07-21
  • 2021-07-05
  • 2021-07-15
相关资源
相似解决方案