sql

Select Column info and join with constraint info

Hi! How can I join these 2 queries to get all table info in one result? A - Get all columns and their datatype belonging to table Customers select COLUMN_NAME, DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'Customers' B - Get all constraints on the table Customers SELECT KCU1.CONSTRAINT_NAME AS 'ConstraintName'...

Mysql query with wildcard on number strings

I am trying to query a mysql table which contains strings of numbers (i.e. '1,2,3,4,5'). How do I search to see if it has '1' but not '11' bearing in mind if it is '9,10' '9%' doesnt work?? Fixed! (field like '10' OR field like '%,10,%' OR field like '%,10' OR field like '10,%') ...

How can I do a BEFORE UPDATED trigger with sql server?

I'm using Sqlserver express and I can't do before updated trigger. There's a other way to do that? ...

Performance questions for SQL Cache Dependency

I'm working on a project where we are thinking of using SQLCacheDependency with SQL Server 2005/2008 and we are wondering how this will affect the performance of the system. So we are wondering about the following questions Can the number of SQLCacheDependency objects (query notifications) have negative effect on SQL Server performance...

How do I spool to a CSV formatted file using SQLPLUS?

I want to extract some queries to a CSV output format. Unfortunately, I can't use any fancy SQL client or any language to do it. I must use SQLPLUS. How do I do it? ...

Does the order of conditions in there where clause affect the speed of the query?

Does the order of conditions in there where clause affect the speed of the query? For instance, could: select fname, lname from people where isValid = 1 and lname like '%test%' be faster than select fname, lname from people where lname like '%test%' and isValid = 1 Duplicate: Does the order of columns in a WHERE clause matter...

Invalid scale size. Cannot be less than zero

I am using spring-2.5.6 to connect from a standalone application to an Oracle 10g database (ojdbc14.jar) using the org.apache.commons.dbcp.BasicDataSource. When I try to retrieve a SqlRowSet using the public SqlRowSet queryForRowSet(String sql, Object[] args) throws DataAccessException method I am getting an 'java.sql.SQLException: Inval...

Modify master.dbo.syslanguages or insert new language

In my application we have to call SET DATEFORMAT YMD before each and every operation. In the master.dbo.syslanguages in entry for my language (polish, lcid=1045) there is dmy format. So is there any way I could change this entry or create a new language that will be like old one, but with changed DATEFORMAT? ...

DB Connection Pool Size Reasonable Limit?

Our pool size is set to 600 connections for our web app to our database. However I just got an email from the client saying they are pushing our training course to 4000+ users telling them that they should get it completed by the 27th of this month. Should I up it to 4000? ...

Mixing ON and USING within one join

Is there a way to do the following in Oracle: SELECT * FROM Tbl1 JOIN Tbl2 USING (col1) AND ON Tbl1.col2 = Tbl2.col3 ...

Extension of question many to many relationships in same table.

I got a single table and it contain 4 fields 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 hosp...

CommandType.Text vs CommandType.StoredProcedure

Is there any benefit to explicitly using the StoredProcedure CommandType as opposed to just using a Text Command? In other words, is cmd = new SqlCommand("EXEC StoredProc(@p1, @p2)"); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@p1", 1); cmd.Parameters.Add("@p2", 2); any worse than cmd = new SqlCommand("StoredProc"); cmd...

Expand query beyond that specifed in the WHERE clause

There must be a better way of writing this query. I want to select all the data between a pair of dates. Ideally the first and last rows of the result set would be those specifed in the WHERE clause. If those rows don't exist, I want the rows preceeding and following the requested range. An example: If my data is: ... 135321, 20090...

Using "like" in a cursor/query with a parameter in python (django)

Hello, I know this may be something stupid but I decided to ask any way. I've been trying to query something like: cursor.execute("select col1, col2 \ from my_tablem \ where afield like '%%s%' and secondfield = %s order by 1 desc " % (var1, var2) ) Bu...

Simple way to run same .sql script on multiple databases at once?

Is there a simple way in, say Microsoft SQL Server Management Studio to run a saved .sql script on a list of databases? ...

How do I dynamically set the table and field name in an update query?

I'd like to loop over a list of tables. For each table, I'd like to run an update query. Psuedo code: ArrayOfTablesObjects = {['tablename1','fieldname1'],['tablename2','fieldname2']......} foreach @tablename in ArrayOfTablesObjects UPDATE @tablename SET @fieldname = 'xyz' WHERE @fieldname = '123' end foreach ...

Outer Join with some other tables in FROM

FROM [TABELA DE PRODUTOS/ESTOQUE] AS T1 , [TABELA DE PRODUTOS] AS T2 , [TABELA DE MOVIMENTAÇÃO DE ESTOQUE] AS T3 , [TABELA DE FORNECEDORES] AS T4 , [TABELA DE PRODUTOS/ESTOQUE] AS T5 WHERE (((T1.Produto)=[T2].[ID]) ETC So, how can I add a JOIN between those tables ? I need a left join, like: FROM [TABELA DE PRODUTOS/ESTOQUE] <- TABLE...

Does JPA support mapping to sql views?

I'm currently using Eclipselink, but I know now days most JPA implementations have been pretty standardized. Is there a native way to map a JPA entity to a view? I am not looking to insert/update, but the question is really how to handle the @Id annotation. Every entity in the JPA world must have an ID field, but many of the views I have...

Include sql scripts in a VB6 application

I am maintaining an old VB6 application, and would like to include SQL scripts directly in part of the project. The VB6 application should then extract the text of this script and execute it on the server. The reasons for this approach are various - among others, we want to deliver only an updated executable rather than a complete updat...

Deleting a LOT of data in Oracle

I am not a database person, exactly, and most of my db work has been with MySQL, so forgive me if something in this question is incredibly naive. I need to delete 5.5 million rows from an Oracle table that has about 100 million rows. I have all the IDs of the rows I need to delete in a temporary table. If it were a just a few thousand r...