sql

MySQL Update Statement + File Upload

Greetings! Been staring at this all day and can't seem to figure out why my update statement fails to update the field 'image_filename': $fileName = $_FILES['image_filename']; if($fileName["name"] <> ""){ $imageFile = $fileName['name']; $destination = "../../../../assets/resources/images/".$fileName['name']; move_uploaded_fil...

When to INSERT or UPDATE with composite primary key models in ORM?

I've got a homemade ORM system that currently only supports auto-incrementing primary keys. This has worked well, but the time has come to support composite primary keys. I'm aware of the holy war between surrogate vs. composite primary keys, and I personally think there's a place for each. Anyway... :) With an auto-incrementing primary...

tsql- set options

I am rebuilding indexes using a script which reorganises or rebuilds indexes according to a predefined fill factor. It is on SQl 2000. I have the following SET options in my script: SET ANSI_WARNINGS OFF SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON I am getting the following error: DBCC failed because the following SET options have i...

MySQL - Can I combine these 2 SQL statements? Combine JOIN and AVG?

Can I combine these 2 SQL statements? Currently running 2 queries. Trying to tighten up a bit. First one: SELECT * FROM (`cars`) JOIN `brands` ON `brands`.`br_id` = `cars`.`brand_id` WHERE `cars`.`id` = '185707' Second one: SELECT ROUND(AVG(rating)) as avg_rating FROM car_ratings WHERE car_id = 185707 ...

SQL Query including time calculation

Hi, Had a good search here but can't see anything that gets my mind in gear for this one. Basically I have a table call Diaries, this contains fields such as StartTime EndTime, I need to do a calculation that works out the difference in minutes between StartTime and EndTime. then for each row that fits that day I need to add up the res...

MySQL update taking(too) long time ....

After some expected growth on our service all of the sudden some updates are taking extremely long time, these used to be pretty fast until the table reached about 2MM records, now they take about 40-60 seconds each. update table1 set field1=field1+1 where id=2229230; Query OK, 0 rows affected (42.31 sec) Rows matched: 1 Changed: 0 Wa...

SQL Database Structure for Custom Categories

I am creating an online blog website and for each blog post, I'd like to have the user be able to create/edit/delete their own category so that they may categorize their post. What is generally considered a good database design for user generated categories? This is my proposed table design. (Is there a name for this type of db?) USE...

Count and Select Object in ActiveRecord with 1 query

We have objects that we want to represent in stacks (think of stacking items in an MMO). There will be duplicate rows. Let's say our owned_objects table looks like this. user_id | object_id 1 | 27 1 | 27 3 | 46 3 | 46 5 | 59 I want the query to do SELECT user_id, object_id, count(*) AS count FROM ...

Entity Framework with SQLite

I am trying to create entities out of a SQLite database. SQLite doesnt have foreign keys, therefore I cannot map associations between entities. Is there a way to map them somehow? ...

Can MS SQL Server 2000 handle Chinese text encoded with Unicode?

Hi all, Now, I am using Ms sql server 2000 and I want to store my data as the unicode for chinese font. But I don't know it can store this type or not? If not, could anybody guide me? Thanks, Sopolin ...

MySQL Blob to Text (data and datatype)

Hi, I have a mysql database that holds content as a blob, for whatever reason those developers chose to use a blob is out of my control. Is it possible to convert the data to text and the data type to text? ...

generate database & tables schema (ddl) on Oracle pl-sql

Hi, Anyone have a PL-SQL statement that i can use to generate database & tables schema for specific database on Oracle 10g? I need the schema in .sql file and if possible compatible with ANSI-92/99 sql implementation, so i can use the generated .sql directly on sql server 2005. Already heard about exp/imp, but it seems generated dump f...

Is there an advantage on setting tinyint fields when I know that the value will not exceed 255?

Should I choose the smallest datatype possible, or if I am storing the value 1 for example, it doesn't matter what is the col datatype and the value will occupy the same memory size? The question is also, cuz I will always have to convert it and play around in the application. UPDATE I think that varchar(1) and varchar(50) is the sa...

Storing a Windows SID in a Database for Lookup

I have an ASP.NET MVC application where I need to allow to customers configure MembershipProviders based on their environment, but still be able to map that MembershipUser to a concrete User model in our database. Membership.GetUser() will give me access to the logged-in user's Membership.ProviderUserKey. I can use this to relate to a U...

sql counting rows

I have the following table in MySQL... CREATE TABLE `visits` ( `id` int(10) unsigned NOT NULL auto_increment, `visit` datetime NOT NULL default '0000-00-00 00:00:00', `bulletin` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) Where "visit" is the time a visit occurs, and "bulletin" is the article requested at that time. I...

JOIN 3 Rows in 1 Table to 1 Row in another Table

I need to create a recordset which Joins 3 rows from one table on 1 row from another table. At present I have: SELECT * FROM tb_product_sub_cat LEFT JOIN tb_products ON tb_product_sub_cat.category_id = tb_products.product_subcategory WHERE tb_product_sub_cat.category_name = %s I also need: tb_product_sub_cat.category_...

how to compare server time

work on Sql server 2000. i want to get the current server date and time then want to compare it with my table column EntryDate .How to? Declare @id datetime Select @id = DATEPART(hour,GETDATE()) SELECT [Name],[BirthDate],[Email] FROM Customers3 where BirthDate<=@id-1 AND BirthDate>=@id want to get on the range value like @id=10.I wa...

How to converting string builder to string without escape sequence in the converted string

Hi, I am writing some XML data to the stringwriter. I want to pass the values in the stringwriter to the database but when I convert it to a string like StringWriter.GetStringBuilder().ToString() it is converting all the " (double quotes) to \" So when I pass that to database as parameter and when I try to read the data using openX...

SQL replace old values trough new ones

I am trying really hard to solve this problem. I have a table named tbl.Products it has a column named articlenumber which is full of numbers like s401, s402 etc. etc. Now I generated a list with new article numbers which will replace the old ones. It looks like this. s401 I00010 s402 I00020 s403 I00030 s403 I00040 ... I ...

Log every SQL query to database in Rails

I want to save to a log file some SQL query rails performs, (namely the CREATE, UPDATE and DELETE ones) therefore I need to intercept all queries and then filter them maybe with some regexp and log them as needed. Where would I put such a thing in the rails code? ...