sql

mysql updating cell content issue

I am trying to update a value in my database but am recieving the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' ('new_user') VALUES ('1') WHERE 'id'= 5' at line 1 I am trying to UPDATE the table 'users' in the column 'new_...

SQL Constraint/trigger - Is it possible to write a constraint that checks "when you Insert a record it must contain one of two fields"?

Is it possible to have a constraint/trigger on a record being entered that checks if the user has entered at least one of three fields (all of which can be null). For example, I have a database being used to track bugs and new features in other pieces of software. When a bug is discovered a Feature record is created which can have three ...

backup MySQL database with QT

I have a GUI and user can select back up start and end date. Is it possible with a sql query getting back up specific time distance. Thank a lot ...

Data transformation with SQL

I have a table in my database formatted like this: customer old_code new_code C1 A X C1 B Y C2 C Y C2 D Z So the pair of keys customer and old_code map to a new_code. This is great as a way of storing the data, looks ups are very fast, but for human consum...

Safely escaping a variable in a raw SQL query

Im just wondering, would the following be completely safe or would someone be able to get around it using hexadecimal characters, etc: $name = mysql_real_escape_string(htmlentities(stripslashes($_REQUEST['name']))); $query ="SELECT * FROM Games WHERE name LIKE '%{$name}%'"; Thanks. I know I can use PEAR and other libraries to make pr...

how to insert to a identity column using sequences in DB2

Hi, how to insert to a identity column using sequences in DB2? Thanks in advacne ...

Creating a select query that fetches records according to multiple variables

I need to create a select query which fetches records according to multiple variables like: <?PHP @$task=$_REQUEST['task']; @$Country=$_REQUEST['Country']; @$City =$_REQUEST['City']; @$MosqName =$_REQUEST['txtMsqName']; @$PostCode =$_REQUEST['txtPostalCode']; $sql_serch="SELECT Country="."'".$Country."'", " City="."'".$City."'"." FRO...

Where do you store ad-hoc properties in a relational database?

Lets say you have a relational DB table like INVENTORY_ITEM. It's generic in the sense that anything that's in inventory needs a record here. Now lets say there are tons of different types of inventory and each different type might have unique fields that they want to keep track of (e.g. forks might track the number of tines, but refri...

sql query distinct join

Sorry I missed and deleted earlier question on accident again. I have a situation, I am trying to select distinct values from table 1 that are new and store them in table 2. The problem is that table has duplicates on column "name" but it does have a key column "id", but the different ids of course map to the same name. My idea on the...

determining histogram bin size

I'm looking to create a histogram in SQL (which in itself isn't too tricky), but what I'm looking for is a way of splitting the bins so that each bin / band has the same proportion of the data included within. For example if I have the sample data (the value column) and I want to divide it into 5 bins, I know that I can work out the num...

Left Outer Join Query

I have two tables, one for bookings and one for room allocations. Booking table has an id and room allocations table has an id and room_id (id refers to the booking id). I want to find a list of all of the bookings who do not have an entry in the room allocations table. I made the following query: $sql = "SELECT booking.id, booking.use...

Query help need in finding missing numbers

Hi all, I have a table that looks something like this: ID | GROUP ------------------- 1000001 | 0 1000001 | 1 1000001 | 2 1000002 | 0 1000002 | 2 1000002 | 3 1000003 | 1 1000003 | 2 1000003 | 3 1000004 | 0 I need to list all the ids where there is a group missing in the sequence. So for the above...

Initialize to some data, if data is not present in certain fields

I want to put some same value in some fields where data is not present, for that do I need to query each field and see if there is data present or not and accordingly put the data, or there is some other work arround. Like Name Age City N 22 J K K 23 L Here I want to put data on those fi...

How to Delete data from a table which contain self referencing foreign key

This is for a MS SQL 2005 server. I have a query that is deleting all orphaned records in a table. However, this table has self-referencing FKs. I need to delete these as well, but am unclear how to do so. The current script deletes all records that not appear as FKs in other tables, but i didn't take into account the self-referencing...

Show the progress of an SQL Query in Delphi

Is it possible to show the progress of an SQL query in Delphi? For example I have a long complicated query in Firebird and I want to show the user how much percentage of the query has already been completed by the system. Are there any class or component capable of doing this? ...

Good SQL 2000 to 2005 SQL Cleanup tool

Hello, My company is doing an upgrade from 2000 to 2005 and we are taking the oppurtunity to cleanup some of the report queries. One I did today went from 10 minutes to 1:30 fresh and then 2 seconds once SQL has the execution plans. Anyway, what I was looking at the execution plan trying to find more places to cleanup and I noticed a ...

Creating tables in SQL Server 2005 master DB

I am adding a monitoring script to check the size of my DB files so I can deliver a weekly report which shows each files size and how much it grew over the last week. In order to get the growth, I was simply going to log a record into a table each week with each DB's size, then compare to the previous week's results. The only trick is ...

Whats wrong with the query

Query issues, for the life of me i cant figure out what is wrong with this query HAVING distance ='10' GROUP BY c.ancient, c.ant_name, p.upper, p.name, ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY...

TableCardinality

Hi, in MS SQL 2010 What does it means TableCardinality in execution plan? I am looking at data base tuning performances Thanks ...

How do I load an image from a database in ASP.NET MVC?

I have saved an image on the database and want to display it to the user. The table the image is stored in looks like this: Images ------ ImageData Byte ImageName String ContentType String What should I do to load and show it in my View? ...