sql

Good database table design for storing localized versions of data

I'm trying to design some tables to store some data, which has to be converted to different languages later. Can anybody provide some "best practices" or guidelines for this? Thanks ...

Insert a fixed number of rows 2000 at a time in sql server

I want to insert say 50,000 records into sql server database 2000 at a time. How to accomplish this? ...

Database Duplicate Value Issue ( Filtering Based on Previous Value)

Earlier this week I ask a question about filtering out duplicate values in sequence at run time. Had some good answers but the amount of data I was going over was to slow and not feasible. Currently in our database, event values are not filtered. Resulting in duplicate data values (with varying timestamps). We need to process that data ...

Any performance impact in Oracle for using LIKE 'string' vs = 'string'?

This SELECT * FROM SOME_TABLE WHERE SOME_FIELD LIKE '%some_value%'; is slower than this SELECT * FROM SOME_TABLE WHERE SOME_FIELD = 'some_value'; but what about this? SELECT * FROM SOME_TABLE WHERE SOME_FIELD LIKE 'some_value'; My testing indicates the second and third examples are exactly the same. If that's true, my question ...

Catching exceptions as expected program execution flow control?

I always felt that expecting exceptions to be thrown on a regular basis and using them as flow logic was a bad thing. Exceptions feel like they should be, well, the "exception". If you're expecting and planning for an exception, that would seem to indicate that your code should be refactored, at least in .NET... However. A recent scen...

Datagrid usage sourced from SQL server.

I would like to know the best way to use a datagrid control linked to a combination (join) of data tables in a way that both simply allows both display, creation of new rows in underlying tables and deletion. The datagrid appears to offer the latter capabilities but I have not found a way that I am happy with to do more than just displa...

Get top results for each group (in Oracle)

How would I be able to get N results for several groups in an oracle query. For example, given the following table: |--------+------------+------------| | emp_id | name | occupation | |--------+------------+------------| | 1 | John Smith | Accountant | | 2 | Jane Doe | Engineer | | 3 | Jack Black | Funnyman |...

Merging contacts in SQL table without creating duplicate entries

I have a table that holds only two columns - a ListID and PersonID. When a person is merged with another in the system, I was to update all references from the "source" person to be references to the "destination" person. Ideally, I would like to call something simple like UPDATE MailingListSubscription SET PersonID = @DestPerson WHER...

In Access 2003, problem with a memo field if and only if there is a filter on the PK and a sub query is joined.

I have a problem in a query in Acess 2003 (SP3). I have a query that includes some tables and a sub query. The sub query and tables are all joined to a main table. The query uses some aggregate functions and there is a HAVING clause that filters the result on the primary key (PK). Under these conditions, a memo field of the main table ...

Will my index be used if all columns are not used?

I have an index on columns A, B, C, D of table T I have a query that pulls from T with A, B, C in the WHERE clause. Will the index be used or will a separate index be needed that only includes A, B, C? ...

Difference between drop table and truncate table?

I have some tables that I build as a part of my report rollup. I don't need them afterwards at all. Someone mentioned to truncate them as it would be faster. ...

Can you have too many stored procedures?

Is there such a thing as too many stored procedures? I know there is not a limit to the number you can have but is this any performance or architectural reason not to create hundreds, thousands?? ...

What are the different types of indexes, what are the benefits of each?

What are the different types of indexes, what are the benefits of each? I heard of covering and clustered indexes, are there more? Where would you use them? ...

Ajax autocomplete extender populated from SQL

OK, First let me state that I have never used this control and this is also my first attempt at using a web service-- My delima is as follows. I need to querry a database to get back a certain column and use that for my autocomplete. Obviously I dont want the querry to run everytime a user types another word in the textbox, so my best gu...

SQL Server Agent Job - Exists then Drop?

Is there a similar way in SQL to achieve the following, but with sql server agent jobs instead? here's how I do it for stored procedures.. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[storedproc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[storedproc] GO CREATE PROCEDURE [d...

Bulk updating a table from rows from another table

Hi, 2 tables: Employees - EmployeeID - LeadCount Leads - leadID - employeeID I want to update the Employees.LeadCount column by counting the # of leads in the Leads table that have the same EmployeeID. Note: There may be more than 1 lead with the same employeeID, so I have to do a Distinct(SUM(employeeID)). ...

How do you optimize tables for specific queries?

What are the patterns you use to determine the frequent queries? How do you select the optimization factors? What are the types of changes one can make? ...

SQL Null set to Zero for adding

I have a SQL query (MS Access) and I need to add two columns, either of which may be null. For instance: SELECT Column1, Column2, Column3+Column4 AS [Added Values] FROM Table where Column3 or Column4 may be null. In this case, I want null to be considered zero (so 4 + null = 4, null + null = 0). Any suggestions as to how to accomplis...

Encapsulating SQL in a named_scope

I was wondering if there was a way to use "find_by_sql" within a named_scope. I'd like to treat custom sql as named_scope so I can chain it to my existing named_scopes. It would also be good for optimizing a sql snippet I use frequently. ...

Moving from ints to GUIDs as primary keys

I use several referenced tables with integer primary keys. Now I want to change ints to GUIDs leaving all references intact. What is the easiest way to do it? Thank you! Addition I do understand the process in general, so I need more detailed advices, for example, how to fill new GUID column. Using default value newid() is correct, bu...