sql

SQLite3 and Alter table .. after ..

Is there a simple way to modify a table in recent sqlite versions so that it matches a predefined schema? Schema: war_id INTEGER NOT NULL, clanname VARCHAR(64), clanhomepage VARCHAR(128), date DATETIME, server VARCHAR(64), warmode_id INTEGER, squad_id INTEGER, notes TEXT, clantag String(16), PRIMARY KEY (war_id), FOREIGN KEY(w...

string incorrectly translated by ado

I have a database with collation SQL_Latin1_General_CP1_CI_AS. In that database I have a varchar field. There is a row in that database with the string "ó" (single character 243 in codepage 1252). I have a simple ASP page that sets the codepage to 65001, reads that row (using adodb), and sends it out to the browser. Everything works ...

Is there a better way to write this SQL than using WHERE ... IN (subquery)?

is there a better way to write this SQL than using WHERE ... IN (subquery)? SELECT device.mac, reseller.name, agent.name FROM device LEFT JOIN global_user ON device.global_user_id = global_user.id LEFT JOIN agent ON global_user.id = agent.global_user_id LEFT JOIN reseller ON global_user.id = reseller.global_user_id...

SQL Stored Procedure execution time mystery

I'm trying to figure out why a SQL Server stored procedure is executing slowly, so I've put in some crude timers, like this: Create Procedure DoStuff As Begin Declare @Stopwatch datetime Set @Stopwatch=GetDate() Print char(13) + 'Task A' /* Perform Task A */ Print DateDiff(ms, @Stopwatch, GetDate()); Set @Stopwatc...

problem creating a simple relationship in SQL Server 2005

I am using the database diagram to simply drag one column in a table to another to associate them and then trying to save it. i have done this a million times in the past with no problems. Both of the data types are the same, uniqueidentifier. Here is the error I get: 'Customer ' table saved successfully 'CustomerOrder ' table ...

guidance on precomputed SQL attributes

Often I deal with aggregate or parent entities which have attributes derived from their constituent or children members. For example: The byte_count and packet_count of a TcpConnection object is computed from the same attributes of its two constituent TcpStream objects, which in turn are computed from their constituent TcpPacket objec...

Is this how a modern news site would handle it's sql/business logic?

Basically, the below image represents the components on the homepage of a site I'm working on, which will have news components all over the place. The sql snippets envision how I think they should work, I would really appreciate some business logic advice from people who've worked with news sites before though. Here's how I envision it: ...

How do I correctly use "Not Equal" in MS Access?

Objective: The intent of this query is to select all of the distinct values in one column that don't exist in a similar column in a different table. Current Query: SELECT DISTINCT Table1.Column1 FROM Table2, Table1 WHERE Table1.Column1 <> Table2.Column1 Results From Query: What happens when I try to run this query is the progress ...

Sorting SQL row output per an arbitrary order?

So, in my database, I store musical instrument names (and various other attributes). Let's say id is the primary key, and name is a unique key. In a PHP script, I select items by their instrument class, like so: $name = mysql_real_escape_string($_POST['name']); $row = mysql_fetch_row(mysql_query("SELECT * FROM `instruments` WHERE name ...

Many-to-many database design question

Say you have the following many-to-many table relation: user ----- id first_name last_name user_prefs ---------------- id preference_name user2user_prefs ------------- id user_id user_pref_id But say you have the user preference of "homepage" and need somewhere to store the actual homepage url. Where would that go? I can't put a va...

Image Saving explanation

I have manage to write images on an sql server 2008 But i see that in the image record writing the same bytes in all of the images And also it creates on the remote disk under a special catalogue a file which finally is the image Is there anybody which can explain me the flow chart of writing an image in sql server? What is contain...

How do i get the SQL query ID after processing it?

Hi, This a bit looks complicated, i want to get the id column value of the processed query. example: $qu = mysql_query("INSERT INTO msgs (msg,stamp) VALUES('$v1','$v2')"); i want to get the ID of this query after storing the infos in database. if it's impossible, is getting the last ID record and adding 1 will be safe and guaran...

Calculate cost of a phone call in SQL

Q1: A: There are two tables in a telecom SQL Server database – Customers and Rates as shown below: Customers PK CustomerPhoneNumber varchar(15) CustomerType int -the type of customer Rates FK CustomerType int - the type of customer CountryCode varchar(4) – th...

Django model with filterable attributes

I've got two models. One represents a piece of equipment, the other represents a possible attribute the equipment has. Semantically, this might look like: Equipment: tractor, Attributes: wheels, towing Equipment: lawnmower, Attributes: wheels, blades Equipment: hedgetrimmer, Attributes: blades I want to make queries like, wheels = A...

SQL LIKE in Django/Python

I'm trying to run a query like this: SELECT * FROM MyTable WHERE FirstName LIKE '%[user inputted value here]%' OR LastName LIKE '%[that same user inputted value]%' AND UserID = some number When I run the query using cursor.execute(), the inputted values are going to be escaped and quoted, which is causi...

How to delete a "tree" of data from sql?

I have a table structure similar to: Portfolios Properties Units Leases All tables are setup with foreign key relationships and cascade deletes. I want to be able to delete a portfolio, which would in turn delete all properties assigned to that portfolio, all units assigned to those properties, and all leases assigned to tho...

group / sum data based on period of time in SQL Server

I have a customers table and I want to get the growth broken down by different periods say day, week, or year. To simplify let's assume there are only 2 columns: CustomerID, CreatedOn Trying to grasp this concept so I can apply it to several reports I want to make. ...

SQL Group Select Query

Hi, I have the following table: ----------- ---------- ----------- | AccountID | Password | IpAddress | ----------- ---------- -----------| | 1 1234 127.0.0.1 | | 2 123 127.0.0.1 | | 3 1234 127.0.0.1 | | 4 12 127.0.0.2 | | 5 123 127.0.0.2 | | 6 ...

SQL Server JDBC Exception

When using ANT to build my Java application I keep getting this error. I have tried multiple times to use SQLJDBC.JAR and SQLJDBC4.JAR but continually receive this error message. I am completely stumpped why this error is received even after upgrading to sqljdbc4.jar. [javadoc] java.lang.UnsupportedOperationException: Java Runtime...

Zend_Db_Select - Joins and Count - Possible Zend Bug?

I'm having an issue getting a COUNT() from a SQL query using Zend_Db_Table_Select, and I think it may be a possible bug because the SQL it should be generating actually works. Here's the Zend Select Query: ($this is a Zend_Db_Table, renamed to table1 in this example) $select = $this->select(); $select->setIntegrityCheck(false);...