sql

SQL Server, where clauses comparisons with different types & default casting behaviour

Right... this one had me baffled for a while today so maybe one of you SQL Server bright sparks can shed some light on this behaviour. We have a table Phones. In it, the phone numbers are stored as nvarchars and it contains numbers in International format, in only numeric format... so a US number +1-(212)-999-9999 is stored as 121299999...

SQL Query for an Organization Chart?

Hello all, I feel that this is likely a common problem, but from my google searching I can't find a solution quite as specific to my problem. I have a list of Organizations (table) in my database and I need to be able to run queries based on their hierarchy. For example, if you query the highest Organization, I would want to return th...

Optimize SQL Stored Procedure

A stored procedure that runs a SELECT on a large table is timing out. The where clause is causing the timeout, because I am selecting only cities that are in another table. AND city IN (SELECT DISTINCT city from tOH where clientId = @clientId) AND state IN (SELECT DISTINCT state from tOH where clientId = @clientId) *note almost alway...

Best Practices in setting up a Blog data model

I have the following setup for my Blog Data Model: Blog Articles Categories ----- -------- 1 ---------- ID \ 1 * ID /----- ID Name \------------ BlogID / Name Owner Name * / CategoryID-/ I'm worried about how ...

SQL connection Issues.

We are having issues with our sql server. About two times a day we have to restart our server because SQL becomes unresponsive to our web applications. It doesn't look like we have a problem with to many connections, as there are never more then 20 active at a time. The weird thing is I can access sql from MS SQL Enterprise Manager 8.0 ...

SQL Server: Retrieve auto-incremented ID inside a stored procedure?

My database has a parent table with an auto-incrementing primary key identity 'ID', and a normal 'TIMESTAMP column'. I have child tables with a foreign key that refer to the parent 'ID' column. I want to write a stored procedure that inserts a new column into both the parent and child databases. How would I set the child 'ID' column to...

Choosing the right database: MySQL vs. Everything else

It would seem these days that everyone just goes with MySQL because that's just what everyone goes with. I'm working on a web application that will be handling a large quantity of incoming data and am wondering if I should "just go with MySQL" or if I should take a look at other open-source databases or even commercial databases? Thanks...

Using IN clause in a native sql query

We are trying to dynamically generate an IN clause for a native sql query to return a JPA entity. Hibernate is our JPA provider. Our code looks something like this. @NamedQuery( name="fooQuery", queryString="select f from Foo f where f.status in (?1)" ) .... Query q = entityManager.createNamedQuery("fooQuery"); q.setParamete...

SQL query to return 1 through int variable

in SQL Server, if I have an int variable, how can I write a query that returns the values 1 through the int variable's value? So given: declare @cnt int set @cnt = 5 What query would return 1 - 5? Is this possible? ...

Why is there a discrepancy between ActiveRecord SQL and PL/SQL Developer SQL?

I have a select statement in Oracle PL/SQL Developer that's retrieving values based on a date: select * from <table> where to_date(create_date) = to_date('20090506', 'YYYYMMDD') where create_date is of Oracle type date. This returns a non-empty set as it should. However, in ActiveRecord: <Table>.find_by_sql("select * from <table> wh...

SQL: delete all the data from all available tables

I am using oracle DB to maintain more than 30 tables, how can I delete all the data from all the tables? I only want to delete the data but not drop the tables. Thank you so much. ...

How Do I Script a Database To a Text File So That It Can Be Created Again By Anyone?

Hello, I have a database that I have created using SQL Server Developer 2008. I want to script it to a file so that it can be recreated by anyone at any time. Any Ideas? ...

Multiple Update

I'm trying to update two query's in my php script but i can't get it to work. The code is: UPDATE table SET price = '14.50' WHERE type LIKE 'finger', 'Knuckle' AND quantity <=50; Okay, ive fixed the WHERE clause but i don't understand what i need to change with the '14.50' part which is now picking up an error? ...

SQL Query Help: select random employee of the month

Could any one show me how to get record from this statement Select random employee which is not an employee of the month in the last x months Table Employee ID EmployeeName Table EmployeeOfTheMonth ID EmployeeID MonthStartedDate MonthEndedDate Thank you very much ...

Insert data to Sesame Database using SQL queries

Hello, I would like to know whether is possible to add normal data to a Sesame Database using SQL queries and retrieve them through SQL queries..?? Thank you Regards, Chith ...

Java library\application to Build SQL Frontend GUI's

Does anyone know of a java library or application that allows for SQL front end manipulation via java GUI's e.g. Swing or SWT? I am looking for something similar to ASP .Net Datagrid, where you essentially 'plugin' the queries, set a few things up and voila! I've used Spring JDBC quite a bit and have been playing with the JDBC templa...

raiseerror sql server silent message

How can I use ROLLBACK TRANS inside a SQL Server trigger without getting the standard message ? "Msg 3609, Level 16, State 1, Line 1 The transaction ended in the trigger. The batch has been aborted." This is being returned to the client. I would like the ROLLBACK to complete silently. I need to achieve this within the trigger only; i.e...

how to change identity increment of column

Following statement can reset seed DBCC CHECKIDENT ('TableName', RESEED, 1) but this time I have to change its increment . ...

SQL queries taking too long

I'm using ADO to save data to an MS Access database. It was taking quite a while to save the data to file (about 7 seconds - which is too long for our purposes). I looked at the number of SQL queries being run, and it's about 4200; although there isn't a whole heap of data. The database connection seems to be the bottleneck. Do you know...

Slow but simple Query, how to make it quicker?

I have a database which is 6GB in size, with a multitude of tables however smaller queries seem to have the most problems, and want to know what can be done to optimise them for example there is a Stock, Items and Order Table. The Stock table is the items in stock this has around 100,000 records within with 25 fields storing ProductCode,...