sql

find match between 2 sql queries

I have two queries from v$sqlarea. For example query 1: select * from employee emp where emp.eid = 5 query 2: select * from employee v where v.eid = 15 Both are exactly the same in structure. but they will be compiled separately each time.. I need to match such queries that vary only by alias names or bind variables. The inbuilt ...

Speeding up SQL query when sorting on foreign keys

This is more of a generic SQL problem but I'm using Firebird 2.5 if anyone knows of a Firebird/Interbase specific optimization. First, the following is a simplified example schema to illustrate the issue I'm trying to solve: CREATE TABLE users ( id INTEGER PRIMARY KEY, name VARCHAR(16) ); CREATE TABLE data_set ( id INTEGER PR...

Executing Access SQL Query Between Two Databases

I need to execute a SQL Query between two databases. Example: SELECT * from table1 in 'D:\paulo\sdatabases\SCWa.mdb' The problem is that both tables have a password. How can i put the password in a query like this? ...

How do you know when an SQL database needs more normalization?

Is it when you're trying to get data and there is no apparent easy way of doing it? When you find something should be a table on it's own? What are the laws? ...

What if my process is too long for transaction timeout duration?

Hi, I would like to know what are the best practices, if you have a quite long lasting process that ends up with a transaction timeout and which should definitely be possible to rollback if any exception is thrown within? Imagine that all along the application set timeout duration is quite enough but for such a specific one it is not ...

Where is the "LEFT" operator in LINQ?

Using SQL Server 2005 I've run a query like this SELECT * FROM mytable WHERE (LEFT (title, 1) BETWEEN @PREFIXFROM AND @PREFIXTO) I use this to do alphabet filtering, so for example PREFIXFROM = a PREFIXTO = c and I get all the items in mytable between a and c (inclusive) How do I do this in linq? Selecting all the records fine.. bu...

Generic suggestions for SQL 2005 Framework\Design and Implementation

I'm renovating an existing ASP.Net web-app which has a full-fledge functional SQL 2005 DB as its backend. By full--fledge functional I mean that there're many things (infact almost ALL the CRUD operations) that are being handled from within the DB using SP. So, my first question is that is an extensive usage of SP good based on paramete...

SQL UPDATE Loop Non-Sequential Keys

I am writing a C# application that will update the fields in a SQL Server database. The current algorithm I am testing simply pulls the data from a "State" field, stores each value in an ArrayList, capitalizes it, and then writes it back to the database. I am having a problem with logic. I pull all of the values into the ArrayList and c...

fetch data from DB and display it using stored procedure (asp.net)

hello In asp.net(C#) i want fetch data from the database using stored procedure and display them in controls... for exmp... "Name" in textbox1 "contact" num in textbox2 any help as i new with this thanks ...

Hibernate Mapping Two Tables to One Class

I need to map two tables to a single class, having trouble figuring this out. One table is ROOMS, the other is TRAINERS. The ROOMS table: OOC_UNIT_ID NUMBER(6,0) OOC_START_DT DATE OOC_START_TM DATE OOC_DT_MOD DATE OOC_USER_MOD VARCHAR2(30 BYTE) OOC_END_DT DATE OOC_END_TM ...

How can I force my Dataset using application to reconnect and prevent timeout error?

Brief question What command can I use to make my DataSet refresh it's connection to the SQL Server before I go on to work with the DataSet object? I'm working with C# in .Net 2.0 Much longer version of the same question with specifics I have a database application that is often left running for several hours between manually instigat...

SQL Server replace, remove all after certain character

My data looks like ID MyText 1 some text; some more text 2 text again; even more text How can I update MyText to drop everything after the semi-colon and including the semi colon, so I'm left with the following: ID MyText 1 some text 2 text again I've looked at SQL Server Replace, but can't think of a viable w...

How Do SQL Transactions Work?

I have not been working in SQL too long, but I thought I understood that by wrapping SQL statements inside a transaction, all the statements completed, or none of them did. Here is my problem. I have an order object that has a lineitem collection. The line items are related on order.OrderId. I have verified that all the Ids are set and a...

SQL Query to fetch number of employees joined over a calender year, broken down per month.

I'm trying to find the number of employees joined over a calender year, broken down on a monthly basis. So if 15 employees had joined in January, 30 in February and so on, the output I'd like would be Month | Employees ------|----------- Jan | 15 Feb | 30 I've come up with a query to fetch it for a particular month S...

How to rename a constraint when I don't know the name.

I need to rename a constraint in an Oracle databse, but I don't know the old name at design-time. What I would like to do is this: declare vOldName string; begin select CONSTRAINT_NAME into vOldName from user_constraints where TABLE_NAME='AGREEMENT' and CONSTRAINT_TYPE='R'; alter table Agreement rename constraint v...

TSQL - How to return 2 values with one case statement?

Is there a way to use one CASE statement and return 2 different values? Following query has 2 CASE statements with same conditions. select case when DA.value = 1 then da.Good else da.Bad end as Foo, case when DA.value = 1 then ot.Good else ot.Bad end as Bar, from someTable DA (nolock) join otherTable OT (nolock) on OT... wh...

Optimising SQL Query With Multiple Joins

Hello, I have the following three tables: Venues, Events, Instance. Events have a Venue (Venues have many events), and Events have many Instances. For example, the Event "Terminator2" is a film that has a certain cinema as its Venue and will have many instances of that film (date times). I need to run a query, which gives me a lost ...

What does =+ mean in (T)SQL?

I found something like this in a SqlServer DB stored proc: SELECT stuff FROM mytable WHERE mytable.column = + @parameter It seems to run without error, so I assume it's okay. What would the "+" be doing? (Not surprisingly, this is a difficult topic to effectively search on, so I apologize in advance if this is a duplicate.) ...

VARCHAR(MAX) versus VARCHAR(n) in Oracle

Similar question, but for Oracle. Why would I not always want to choose VARCHAR(MAX)? ...

Updating foreign key values

Hello, I have a database application in which a group is modeled like this: TABLE Group ( group_id integer primary key, group_owner_id integer ) TABLE GroupItem ( item_id integer primary key, group_id integer, group_owner_id integer, Foreign Key (group_id, group_owner_id) references Group(group_id, group_owner_id) ) We ha...