公司 sql2005数据库已经用了5年,数据库里面的表记录条数很多导致查询速度越来越慢。有近200个表。有没有什么办法将表中的有用的数据按条件导出到另一个相同结构的数据库中?或者有什么优化的办法也好啊。哪位大侠指点下,感激不尽哈

解决方案 »

  1.   

    select * into newtb from oldtb然后对newtb建立相关主键或索引,约束等内容.
      

  2.   

    如果表已经存在,则如下:insert into newtb select * from oldtb
      

  3.   

    Number of tables (200 is a small number in terms of the tables in a database - large systems typically have thousands if not tens of thousands of tables) has nothing to do with performance. It is how you use these tables (as in how well they are indexed, how well you write your SQL statements) that dictate performance. I have dealt with systems that have millions of records in tables and a dozen rows are returned in subsecond.In general, if you start to run into performance issues, I'd do the following:
    (1) Reindex the entire database
    (2) Run Database Engine Tuning Adviser to determine if any new indices are required
    (3) Run SQL Profiler trace (which you probably will need to use in 2 anyway) and get a feel on the types of queries that are slow and the main tables they are hitting. You can then determine if these tables require normalisation/denormalisation, new indices or a different way of writing queries.