sql

SQL FOR EACH?

I have a table with two columns, userID and contentID. Basically this table is used to assign access to certain content to specific users. I have the request of every user that is assigned to content A also be assigned to content B. So how would I write a new row with this data (userid, [id of content B]) for each row that has (userid, [...

SQL syntax error

I cannot find the error in the following sql: $query = "INSERT INTO users('username', 'password', 'key', 'email', 'rank', 'ip','active') VALUES ('$username','$password','$random','$email','1','$ip', '0')"; For some reason I keep getting the error Error: You have an error in your SQL syntax; check the manual that corresponds to your ...

Dropping a schema and all of its contents in DB2 8.x

How would I drop a schema and all of its contents, using SQL, in DB2 8.x without knowing what the content is? ...

What's the optimal solution for tag/keyword matching?

I'm looking for the optimal solution for keyword matching between different records in the database. It's a classic problem, I've found similar questions, but nothing concretely. I've done it with full text searches, joins and subqueries, temp tables, ... so i'd really like to see how you guys are solving such a common problem. So, let...

Duplicate a row in SQL?

OK I have a table that has two columns, userID and courseID. It is used to assign training courses to a user. It looks like this: userid courseid 0 1 0 3 0 6 1 1 1 4 1 5 so user 0 is assigned to courses 1,3,6 and user 1 is assigned to 1, 4 5 anyways I need to take every user tha...

Online validators, syntax checkers, testing tools

I often need to verify some simple code before posting, and it's great if I have installed IDE, but what if not? It would be nice to have online free tools for SQL, VB.NET, C# code validation, or maybe even testing. EDIT What I actually mean are online live web tools, like JSLint for javascript. Have you seen any? ...

Need in SQL parser on Delphi

Does anybody know about good SQL parser with sources, written in Delphi? I need in parsing SQL commands (with all new features of Firebird 2.5) into object structure. ...

Access query returns empty fields depending on how table is linked

I've got an Access MDB I use for reporting that has linked table views from SQL Server 2005. I built a query that retrieves information off of a PO table and categorizes the line item depending on information from another table. I'm relatively certain the query was fine until approximately a month ago when we shifted from compatibility...

What's your favored method for debugging MS SQL stored procedures?

Most of my SPs can simply be executed (and tested) with data entered manually. This works well and using simple PRINT statements allows me to "debug". There are however cases where more than one stored procedure is involved and finding valid data to input is tedious. It's easier to just trigger things from within my web app. I have a...

Calculate the Last Day in the CURRENT quarter

What's the most efficient way to calculate the last day of the CURRENT quarter? Example: given the date 3/5/09, I want to return 3/31/09. Platform is ColdFusion and SQL Server ...

What is the best way to empty a self-referential MySQL table?

I have a self-referential MySQL table with a recursive parent_id: CREATE TABLE `recursive` ( `id` int(11) NOT NULL auto_increment, `parent_id` int(11) default NULL, `name` varchar(100) NOT NULL, PRIMARY KEY (`id`), KEY `data_categorysource_parent_id` (`parent_id`), CONSTRAINT `parent_id_refs_id_627b4293` FOREIGN KEY (`p...

What is the best way to transfer a table or tables from one SQL server to another?

I have been developing in VB.NET and SQL Server 2008 for a while now, but haven't got into live installs yet. In the database system I used be on it had the ability to archive multiple tables into a .dga file, as it was called. I could then restore the .dga file into another database or on another server. I'm looking for the easiest way...

How do you break circular associations between entities?

Hi all, my first time on the site so apologies if it's tagged incorrectly or been answered elsewhere... I keep running into particular situation on my current project and I was wondering how you guys would deal with it. The pattern is: a parent with a collection of children, and the parent has one or more references to particular items...

Quick & Dirty Way of Disabling a Particular Foreign Key

Ideally I would have a "isActive" field in the table to indicate if a record is active, but it would involve changes in multiple stored procedures to make the field do what it is meant to do. I came up with a dirty trick, and kind of tempted to carry it out. Since the result set is generated by a few joins, I was thinking of slightly c...

SQL Insert Performance Improvement

I am writing an application that logs status updates (GPS locations) from devices to a database. The updates occur at a set interval for each device, which is currently every 3 seconds. I'm using a simple table in SQL Server 08 for storing each update. I've noticed that running the inserts is an area of slow down in my application. I...

TSQL - When to use 'not null'

What general guidelines should I go by when considering whether I should mark a field 'not null' as opposed to just declaring everything but the primary key null? Should 'not null' fields have DEFAULT values? ...

Is there a performance issue when using inline SQL statements rather then using a DAL design?

I made a fairly large social network type website and used nothing but inline SQL Statements to access the database (I was new to the language so back off!) Are there any performance issues when doing it this way as opposed to using a massive XSD DataSet file to handle all the queries? Or is this just bad design? Thanks! ...

How to create a query by renter to summarize multiple rent transactions within a given month

Goal: To show all property units by property rather vacant or not with renter info and summary of all payments (by each rent, late, utilities) made in a given month. eg if renter makes partial payments Do not want to show each partial but summarize into one record. Here is as close as I can get. The challenge is if the renter makes mult...

Getting the data out of one-many relation ship from same table

Hi, I have a single table and it contains 4 columns: Id|Hospital| Doctor|patient 1 A D1 P11 2 B D6 P61 3 A D2 P21 4 A D1 P12 5 B D7 P71 6 B D6 P62 7 B D6 P63 Doctors are unique to the Hospital. They don't work in other ho...

Keep a log of file access time

So we have a few (or more, no one knows) apps written by someone who has now left, these apps access Microsoft Access Databases stored on this developers old PC, which in turn read from our Production SQL database. Now to track all these programs down, and what time they are run, I'd like to keep a log of a files access time, is this pos...