sql

Select all columns from all tables in SQL Server 2008

How can I Select all columns from all tables from the DB, like: Select * From * in SQL Server 2008??? The table list it´s very very big, and have so many columns, is it possible to do it without writing the column names? Or maybe make a select that returns the name of the tables. ...

How to match people between separate systems using SQL?

I would like to know if there is a way to match people between two separate systems, using (mostly) SQL. We have two separate Oracle databases where people are stored. There is no link between the two (i.e. cannot join on person_id); this is intentional. I would like to create a query that checks to see if a given group of people from ...

Oracle Missing Right Parenthesis

Here is my query: SELECT * FROM Auta WHERE SUBSTR(spz, 1, 2) = (SELECT SUBSTR(spz, 1, 2) FROM Auta WHERE typ = 'BMW' AND specifikacia_typu = 'Z1' LIMIT 1); And when I run it I get this error: ORA-00907: missing right parenthesis I'm getting a little desperate, I've already tried adding parentheses everywhere in the query and I sti...

Testing Stored Procedures with MySQL

What is the best way to test MySQL stored procedures? How do you test stored procedures with output parameters in the MySql GUI? ...

Does order of boolean statements make a performance difference in a MySQL query?

Suppose I want to query a table based on multiple WHERE clauses. Would either of these statements be faster than the other? SELECT * FROM table WHERE (line_type='section_intro' OR line_type='question') AND (line_order BETWEEN 0 AND 12) ORDER BY line_order"; ...or: SELECT * FROM table WHERE (line_order BE...

CakePHP inefficient database queries: can they be avoided?

My table structure: boxes (id, boxname) boxes_items (id, box_id, item_id) I was looking at the SQL logs for the "delete box" action, and am slightly horrified. SELECT COUNT(*) AS count FROM boxes Box WHERE Box.id = 191 SELECT BoxesItem.id FROM boxes_items BoxesItem WHERE BoxesItem.box_id = 191 SELECT COUNT(*) AS count FROM boxes_item...

How do constant values effect the ON clause of Joins?

I've recently discovered that the ON clause of a LEFT JOIN may contain values such as (1 = 1). This is upsetting to me, as it breaks my perception of how joins function. I've encountered a more elaborate version of the following situation: SELECT DISTINCT Person.ID, ... FROM Person LEFT JOIN Manager ON (Manager.ID = Person.ID OR Mana...

SQL Server 2005 - Pivoting Data without a sum / count and dynamic list of values

Sorry if this is covered elsewhere in another question, but I can't find any examples which exactly match what I need and I'm getting confused. I have data in the table like this :- Name | Value --------------- John | Dog John | Cat John | Fish Bob | Python Bob | Camel And I would like the data like this.......

Stored procedure search using entity framework

Hi everyone. I want to implement a search logic that I have seen and use. It works like this: There is stored procedure that is loaded in entity framework and it is used as a method in C#, it takes parameters in order to perform search. That method is returning list of views (DB View). The views in list have just some of the properti...

Where can I learn the SQL way to get data out

There's a gap in my SQL knowledge I'd like to fill and I'm after recommendations on where to find resources, eg. websites, how-tos, books, etc. I've been using SQL databases for a long time. I'm quite comfortable with: basic SQL and its syntax; creating tables and indexes; inserting data; and basic DBMS maintanenance. Where I struggle ...

How to quickly edit values in table in SQL Server Management Studio?

Aside from context menu -> "Edit Top 200 Rows" from Object Explorer, is there a quick way to open a table in Edit mode where I can just quickly modify the value of a cell? I need to be able to page past the first 200 rows. And I dont want to write "insert" script for every minor tweak I need to do... I don't understand why SMS doesn't...

ASP.NET Query with parameters

Please help me, I don't know what can be wrong with the following code: OdbcConnection conn = new OdbcConnection(connString); String query = "INSERT INTO customer (custId, custName, custPass, "+ "custEmail, custAddress, custAge) VALUES (" + "@ID, @Name, @Pass, @Email, @Addres...

Translate SQL to linq-to-sql (subquery)

How to I convert the following SQL statement into LinqToSQL? select t1.name, (select COUNT(*) from table2 where t2.f_id = t1.id) as cnt from table1 t1 My attempts seem to end up doing an inner join (and therefore giving wildly inaccurate results). Thanks ...

SQL*Loader problem

I am getting an error SQL*Loader-606, which means: The synonym specified in the INTO TABLE clause in the SQL*Loader control file specifies a remote object via a database link. Only a synonym for an existing local table can be specified in the INTO TABLE clause. Is there any way we can insert into remote table using SQL*Lo...

Which one is faster?

Which one is faster? SELECT FROM A INNER JOIN B ON A.ID = B.ID ...or: SELECT FROM A , B WHERE A.ID = B.ID ...

Sql Server 2005 Returns Results From Some Other SP

I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything was working fine from many months. But suddenly we have started getting the following error. System.ArgumentException; Column < ColumnName > does not belong to table < TableName > I wrote come extra logging code to troubleshoot this i...

Getting multiple records on year wise.

Hi All, I have a Patient information table with ~50 million records. I need to check some samples for each year which may be in any order. Here are the sample date available in database "20090722", "20080817", ... "19980301". Also i have a primary-key column called "PID". My requirement is to get 2 or 3 samples for each year with a...

Selecting most popular Foo by count of Bars

Restated question: I have foo. Foo has many fizzs. Fizz has Foo. Bar has one fizz. I want to find foo, which has fizz with the highest count of bars that reference it using LINQ . It would be perfect, if linq would be NHibernate.Linq compatible. But that's already a different story. Old question: I know - question is simple. I've ...

What should a SQL Parameter be in a update statement be when it's not required

As the the question says, what should I set the value of a parameter to if I don't want it to update the DB? e.g. UPDATE table1 SET col1 = @someval , col2 = @someotherval WHERE col3 = 1; If in my c# logic I decide that col2 does not need to be updated because the value being passed in is null, what should I set the parameters val...

[SQL] Retreive/update rows with a minimal deviation in a certain column value

I have a database table with one column being dates. However, some of the rows should share the same date but due to lag on insertion there's a one second difference between them. The insert part has been fixed already but the current data in the table needs to be fixed as well. As an example the following data is present: 2008-10-08 1...