What would happen if a DataSet was returned duplicate named columns from SQL? - asp.net

I am creating as stored procedure that brings back a bunch of data that I need from multiple tables, however the tables share some duplicate column names. It works fine in SQL but I am wondering what will happen and how I will differentiate between them once I am accessing them as DataRows from a DataSet. Anyone know?

It should automatically rename them by appending a number. For example, COLUMN_NAME, COLUMN_NAME1, and COLUMN_NAME2. But, this is difficult at best to maintain, and could cause trouble later.
To avoid this, you'll probably want to specify the names yourself using column aliases (the AS keyword):
SELECT t1.myColumn AS t1_col, t2.myColumn AS t2_col
FROM t1, t2

Related

Moving data in Access 2010

I'm a bit inexperienced but have a managed to learn how to use my database (access2010) but now I need to remove old files. In the database I have a primary table with multiple tables which stores additional information such as my notes.
I can't seem to figure out how to remove old files based on an input date.
I want to remove all files and the data stored in the dependent tables completely from year 2011 and back after backing up the database.
I've tried a delete query, and I've tried to simply copy and past inside the tables. I know there has to be a way to do this without deleting individual files.
When I run a delete query I get invalid key errors and when I delete files from my primary table, I get errors indicating there are associated data stored in the other tables.
Since I can't seem to delete all data across all tables for a certain date range, can anyone point out what I might be doing wrong?
You will need to JOIN the additional tables to your "primary" table, include a WHERE clause to only delete those matching your date range.
For an example, see this answer https://dba.stackexchange.com/a/102738

How do I ignore a column in a tSQLt AssertEqualsTable?

Is it possible to ignore certain columns that are almost definitely going to be different in a tSQLt AssertEqualsTable? Examples would be primary keys from the two results tables, insert/update date stamps, and so on.
I have been working around this by selecting only the relevant columns into new temp tables and comparing those instead, but this means extra work and extra places to make mistakes. Not a lot, sure, but it adds up over dozens or hundreds of tests.
A built-in or simple way to say 'compare these two tables but ignore columns X and Y' would be very useful. Is there a better solution than the one I'm using?
All you need to do is populate an #expected table with the columns you are interested in. When AssertEqualsTable does the comparison it will ignore any columns in the #actual table that don't exist in the #expected table.

RODBC not following order to dataframe when importing into access mdb file

As title, I created a dataframe and import it into mdb file using RODBC in R. Things are going OK, but I realize that the table shown in mdb file is not having the same order as my dataframe. I tried using row.names(temp.df) <- NULL after ordering, but the order is still kinda random.
It is not a very big issue as long as the two datasets are the same, but I wonder why this will happen.
Thanks.
Databases generally have no concept of ordering of their rows, by design. If you want a particular sorting order, then you have to put "ORDER BY" in your SQL when working with a database and sort on a column.

sqlite3 insert into dynamic table

I am using sqlite3 (maybe sqlite4 in the future) and I need something like dynamic tables.
I have many tables with the same format: values_2012_12_27, values_2012_12_28, ... (number of tables is dynamic) and I want to select dynamically the table that receives some data.
I am using _sqlite3_prepare with INSERT INTO ? VALUES(?,?,?). Ofcourse this fails to compile (syntax error near ?). There is a nice and simple way to do this in sqlite ?
Thanks
Using SQL parameters is not possible for identifiers such as table or column names.
If you don't want to keep so many prepared statements around, just prepare them on the fly whenever you need one.
If your database were properly normalized, you would have a single big values table with an extra date column.
This organization is usually to be preferred, unless you have measured both and found that the better performance (if it actually exists) outweighs the overhead of managing multiple tables.

How to determine position of specific character/string in SQLite string column value?

I have values in a SQLite table* that contain a number of strings, of different lengths, joined by periods, something like this:
SomeApp.SomeNameSpace.InterestingString.NotInteresting
SomeApp.OtherNameSpace.WantThisOne.ReallyQuiteDull
SomeApp.OtherNameSpace.WantThisOne.AlsoDull
SomeApp.DifferentNameSpace.AlwaysWorthALook.LittleValue
I'd like to extract (in this case) the third period-delimited substring so I could write something like
SELECT interesting_string, COUNT(*)
FROM ( SELECT third_part_of_period_delimited_string(name) interesting_string )
GROUP BY interesting_string;
Obviously I can do this any number of ways programmatically; I'm wondering if there's any way to achieve this in a SQLite SELECT query?
* It's a SharpDevelop Profiler database, if anyone's curious
No.
You can, as you mention, work with the strings after you have selected them from the database. Or you can split them up into separate columns when they are stored.
If you do not have access to the code that is storing the data, you might want to consider reading the data in its entirety, splitting the strings and storing the split out tokens in separate columns in a new table. If the data is not too large, you might look at storing this table in a new memory database to give excellent performance.
Whether this is worthwhile depends on whether one pass to split the data strings can be made use of many times. If the data is constantly changing, then this scheme would probably not work well.

Resources