sql

Relations between 3 mysql tables

Hello. I have 3 mysql tables: events, artists and (artist) descriptions. All of them are in many-to-many relations. Table 'events': ID | eventTitle | etc. ----------------------- 1 | event 1 | 2 | event 2 | etc. Table 'artists': ID | artistName | etc. ----------------------- 1 | artist 1 | 2 | artist 2 | etc. T...

mysql datetime field

I'm parsing a feed that contains a "created at" entry, formatted like this: Thu, 08 Oct 2009 23:01:33 +0000 I need to be able to store this in a MySQL table, in a DateTime datatype. Then, I want to select rows WHERE datetime clause equals or in range between dates and/or times. I have two questions: Will this string be acceptable ...

Join 3 tables in 1 LINQ-EF

I have to fill warehouse table cOrders with program using Ado.NET EF. I have SQL command but i don't know how to do this with LINQ. static void Main(string[] args) { var SPcontex = new PI_NorthwindSPEntities(); var contex = new NorthwindEntities(); dCustomers dimenzijaCustomers = new dCusto...

How to Query and Dump Results Into Table In Access

Need to query my SQL server from Access using an ADO connection (for example), and then using something like: Currentdb.CreateTableDef() in Access to create a table (in Access) with the query results. How can I do this? ...

i forgot the SQL 2005 tool that helps me extract the database into scripts

Hello, I forgot the name of that application tool. anyone here remembers it? It let's me log-in to my remote SQL database and I can create scripts of the schema and procedures and even data. ...

SQL double SELECT on the same field (mysql or sqlite3)

Hi, i have a problem that i can't solve ! (sqlite3, but i think it would be the same than MySql) I have those tables (image) : And i would like to find all the bus lines (with type and number) that go to two different streets from which i have the street_id (12 and 14 for exemple). The result shall give to the customer all of the bus...

How to use DATEDIFF to return year, month and day?

How can I use DATEDIFF to return the difference between two dates in years, months and days in SQL Server 2005 DATEDIFF (date , date) How to result that: 2 year 3 month 10 day Can anyone complete this t-sql? ALTER FUNCTION [dbo].[gatYMD](@dstart VARCHAR(50), @dend VARCHAR(50)) RETURNS VARCHAR(50) AS BEGIN DECLARE @yy INT DEC...

MySQL: optimizing a JOIN query

Say I have two MyISAM tables: tab_big: id1, id2, id_a, ord (5 billion records) tab_small: id1, id2, id_b (1 billion records) CREATE TABLE IF NOT EXISTS `tab_big` ( `id_a` int(10) unsigned NOT NULL, `id1` int(10) unsigned NOT NULL, `id2` int(10) unsigned NOT NULL, `ord` int(10) unsigned NOT NULL DEFAULT '...

insert now() into a Sybase timestamp field

I'm new to sybase and google was anything but helpful. All I want to do is insert a valid time for "right now" into a timestamp field. The mysql equivalent is now(). I tried getdate() and got funny results. Thanks. ...

SQL query no order by question

Got into a heated debate (all caps sentences were involved) with a bunch of friends In SQL, create table test( id int, code varchar(10), name varchar(30) ) insert into test values (1,'BE','BENGALOORU') insert into test values (2,' CH','CHENNAI') insert into test values (3,' DE','DELHI') insert into test values (4,'MU','MUM...

Finding most specific prefix with SQL

I have a bit of an SQL problem. Here are my tables: areas(id, name, sla_id) areas_groups(id, group_id, areaprefix) The sla_id is an identifier from a different source - it is unique, but areas has its own auto-incrementing primary key. The areaprefix field is the interesting one. It just contains the first few digits of the sla_id an...

Simple Linq question: How to select more than one column?

Hi, my code is: List<Benutzer> users = (from a in dc.Benutzer select a).ToList(); I need this code but I only want to select 3 of the 20 Columns in the "Benutzer"-Table. What is the syntax for that? ...

Is it possible to insert into a table variable without defining the schema?

Hi all, Is it possible to insert into a table variable without defining the schema? I need to do this like Declare @tab1 as table Insert into @tab1 select * from table2 Select * from @tab1 I was trying this query but got error. Please help. ...

Getting the next ID without inserting a row.

Is it possible in SQL (SQL Server) to retrieve the next ID (integer) from an identity column in a table before, and without actually, inserting a row? This is not necessarily the highest ID plus 1 if the most recent row was deleted. I ask this because we occassionally have to update a live DB with new rows. The ID of the row is used in ...

Explanation about a code fragment

I see the following code fragment in a legacy application that accesses Informix through C. Can anyone explain what the SQL in the code is trying to achieve? Thanks. EXEC SQL BEGIN DECLARE SECTION; int i_tableref; EXEC SQL END DECLARE SECTION; /* Some code here */ if (!i_sel_ref) { exec sql begin declare section; const char *sql...

SQL: Order randomly when inserting objects to a table

I have an UDF that selects top 6 objects from a table (with a union - code below) and inserts it into another table. (btw SQL 2005) So I paste the UDF below and what the code does is: selects objects for a specific city and add a level to those (from table Europe) union that selection with a selection from the same table for objects t...

No duplicates in SQL query

I'm doing a select in MySQL with an inner join: SELECT DISTINCT tblcaritem.caritemid, tblcar.icarid FROM tblcaritem INNER JOIN tblprivatecar ON tblcaritem.partid = tblprivatecar.partid INNER JOIN tblcar ON tblcaritem.carid = tblcar.carid WHERE tblcaritem.userid=72; Sometimes I get duplicates of tblcaritem.caritemid in the result. ...

How to enforce DB integrity with non-unique foreign keys?

I want to have a database table that keeps data with revision history (like pages on Wikipedia). I thought that a good idea would be to have two columns that identify the row: (name, version). So a sample table would look like this: TABLE PERSONS: id: int, name: varchar(30), version: int, ... // some data assigne...

SQL Server 2008: N small databases VS 1 database with N schemas

I have a database server with few main databases, and few dozens of small ones. These small databases are kind of intermediary/staging databases for data import from various sources into main database. Data import is a daily task. They are all quite similar in structure as the implementation of these data imports are similar, so basical...

Fetch Single Item Using DataContext

I'm doing the following: public MyItem FetchSingleItem(int id) { string query = "SELECT Something FROM Somewhere WHERE MyField = {0}"; IEnumerable<MyItem> collection = this.ExecuteQuery<MyItem>(query, id); List<MyItem> list = collection.ToList<MyItem>(); return list.Last<MyItem>(); } It's not very elegant really and I was hopi...