sql-server-2005

Which is better: Bookmark/Key Lookup or Index Scan

孤街醉人 提交于 2019-12-17 22:37:33
问题 I know that an index seek is better than an index scan , but which is preferable in SQL Server explain plans: Index seek or Key Lookup (Bookmark in SQL Server 2000)? Please tell me they didn't change the name again for SQL Server 2008... 回答1: Index seek, every time. Lookups are expensive, so this is covering indexes and especially the INCLUDE clause was added to make them better. Saying that if you expect exactly one row, for example, a seek followed a lookup can be better than trying to

How often should the indexes be rebuilt in our SQL Server database?

喜欢而已 提交于 2019-12-17 22:29:33
问题 Currently our database has size 10 GB and is growing by around 3 GB per month. Often I hear that one should from time to time rebuild the indexes, to improve the query execution time. So how often should I rebuild the indexes in the given scenario? 回答1: There's a general consensus that you should reorganize ("defragment") your indices as soon as index fragmentation reaches more than 5 (sometimes 10%), and you should rebuild them completely when it goes beyond 30% (at least that's the numbers

How can I copy data records between two instances of an SQLServer database

馋奶兔 提交于 2019-12-17 22:26:49
问题 I need to copy some records from our SQLServer 2005 test server to our live server. It's a flat lookup table, so no foreign keys or other referential integrity to worry about. I could key-in the records again on the live server, but this is tiresome. I could export the test server records and table data in its entirety into an SQL script and run that, but I don't want to overwrite the records present on the live system, only add to them. How can I select just the records I want and get them

IF EXISTS, THEN SELECT ELSE INSERT AND THEN SELECT

天大地大妈咪最大 提交于 2019-12-17 22:07:01
问题 How do you say the following in Microsoft SQL Server 2005: IF EXISTS (SELECT * FROM Table WHERE FieldValue='') THEN SELECT TableID FROM Table WHERE FieldValue='' ELSE INSERT INTO TABLE(FieldValue) VALUES('') SELECT TableID FROM Table WHERE TableID=SCOPE_IDENTITY() END IF What I'm trying to do is to see if there is a blank fieldvalue already, and if there is then return that TableID, else insert a blank fieldvalue and return the corresponding primary key. 回答1: You need to do this in

Can you search SQL Server 2005 Stored Procedure content?

假如想象 提交于 2019-12-17 21:58:40
问题 SQL Server Server 2005. I'm staring at a database that has 500+ stored procedures, and trying to glean the intricacies of how they interact with the data - particularly in regards to how they insert/modify data. I was hoping to find a search" or "find" functionality that would look at the content of the actual procedure. That way, I could do a search for all procedures that do anything at all with some_table_name. The basic find functionality of SQL Management Studio looks in opened files,

In SQL Server 2005, can I do a cascade delete without setting the property on my tables?

倖福魔咒の 提交于 2019-12-17 21:46:19
问题 I have a database full of customer data. It's so big that it's really cumbersome to operate on, and I'd rather just slim it down to 10% of the customers, which is plenty for development. I have an awful lot of tables and I don't want to alter them all with "ON DELETE CASCADE", especially because this is a one-time deal. Can I do a delete operation that cascades through all my tables without setting them up first? If not, what is my best option? 回答1: Combining your advice and a script I found

Restore database backup over the network

偶尔善良 提交于 2019-12-17 21:44:39
问题 How do you restore a database backup using SQL Server 2005 over the network? I recall doing this before but there was something odd about the way you had to do it. 回答1: The database is often running as a service under an account with no network access. If this is the case, then you wouldn't be able to restore directly over the network. Either the backup needs to be copied to the local machine or the database service needs to run as a user with the proper network access. 回答2: You have few

How to average/sum data in a day in SQL Server 2005

假装没事ソ 提交于 2019-12-17 21:25:42
问题 I'm trying to average data in SQL Server 2005 in a day. Here is what my database look like this if I use simple query as SELECT timestamp, FEED FROM ROASTER_FEED ORDER timestamp Data: timestamp Feed 02/07/2011 12:00:01 1246 02/07/2011 12:00:01 1234 02/07/2011 12:00:01 1387 02/07/2011 12:00:02 1425 02/07/2011 12:00:03 1263 ... 02/07/2011 11:00:01 1153 02/07/2011 11:00:01 1348 02/07/2011 11:00:01 1387 02/07/2011 11:00:02 1425 02/07/2011 11:00:03 1223 .... 03/07/2011 12:00:01 1226 03/07/2011 12

SQL Server 2005 restore one schema only

亡梦爱人 提交于 2019-12-17 21:11:44
问题 I am pretty sure this isn't possible.... We have a database with several schemas. Each schema belongs to a different user. One user was asking "if I find out I made a whole load of errors would it be possible to revert to the state my data was in yesterday". Obviously we could restore the whole database, but that would restore the other schemas as well which we do not want to do.... 回答1: You are correct, it is not possible to restore a single schema only. That said, had you stored all

SQL Performance slow when accessing most recent records

前提是你 提交于 2019-12-17 20:51:57
问题 I have a MSSQL2005 database that has records dating back to 2004, there are currently just under 1,000,000 records in one particular table. Thing is, if I run a report comparing 2009 data against 2010 data, 2008 against 2009, 2009 against 2009 or any combination of years before this year then results are returned in 1-5 seconds. If however I run a report that includes 2011 data then the report takes ~6 minutes. I've checked the data and it looks similar to previous years and is cross