sql

Java - retrieving large amounts of data from a DB using iBatis

I need to extract data from a DB2 table, run some processing on each returned row and output to a flat file. I'm using iBatis but found that using the queryForList I started getting out of memory errors, I'll be looking at 100k+ rows of data increasing. I've looked at using queryWithRowHandler instead but the iBatis RowHandler interfac...

How can I drop all indexes in a SQL database with one command?

So, how can I drop all indexes in a SQL database with one command? I have this command that will get me all the 20 or so drop statements, but how can I run all of those drop statements from this "result set"? select * from vw_drop_idnex; Another variation that gives me the same list is: SELECT 'DROP INDEX ' + ix.Name + ' ON ' + OB...

Not sure if I understand what an Indexed View does behind the scenes, in SqlServer

Hi folks, I'm using sql server 2008 and have started to find using Indexed Views are helping me speed up some of my queries ... as my schema isn't basic. So, if i have a table that is the following... **ParentTable ParentId INT PK IDENTITY Name VARCHAR(MAX) **ChildTable ChildId INT PK IDENTITY ParentId INT (FK to the table above) Nam...

How can I make a stored procedure return a "dataset" using a parameter I pass?

I'm very new to Stored Procedures. Say I have a IDCategory (int) and I pass that to a stored procedure. In normal-talk, it'd go: Find me all the listings with an IDCategory equal to the IDCategory I'm telling you to find. So it would find say 3 listing, and create a table with columns: IDListing, IDCategory, Price, Seller, Im...

TSQL, how to avoid if conditions?

Hello SQL Gurus, I am from procedure programming background, end up writing TSQL recently with my new job. My mindset still thinking about writing queries with if conditions. How to avoid following query without if condition. DECLARE @NumAddress INT SELECT @NumAddress = COUNT(*) FROM Address WHERE UserID = 1001 IF @NumAddress ...

Creating a table in SQL Server Express

I'm trying to setup a SQL database for a local program management and install system. I think i've created a basic serviceable schema that should work, but i'm unsure how to translate it to a CREATE TABLE command. Can someone help me with the translation and/or point me to resources that will? Schema: Programs( progID[key] (integer...

SQL QUERY replace NULL value in a row with a value from the previous known value

I have 2 columns date number ---- ------ 1 3 2 NULL 3 5 4 NULL 5 NULL 6 2 ....... I need to replace the NULL values with new values takes on the value from the last known value in the previous date in the date column eg: date=2 number = 3,...

What is the Point of using a Unique index on a Guid Column

Since, guid values will always be unique anyway why use a unique index. Isnt it true that when you use a unique index that it slows down inserts? ...

Link one table to another?

i'm trying to set up some tables in my SQL Express server, and i want to do something to the effect of this: create table programs ( progid int primary key identity(1,1), name nvarchar(255), description nvarchar(500), iconFile nvarchar(255), installScript nvarchar(255) ) however i want each "program" to have a set ...

How to have multiple join constrains in Zend_Db_Select

Hi, How can I do a join such as : LEFT JOIN table1 t1 ON t1.foo = t2.bar AND tl.baz = t2.bat What I'm looking for is the syntax for adding a second join constraint to the leftJoin() method using Zend_Db_Select in the Zend Framework. Thanks, ...

What is the difference between utf8_general_ci and utf8_unicode_ci in MySql?

Are there any big differences a developer should care about? ...

SQL - Select rows based on a hierarchy of conditions

Hi All It would be great if there was a POSITIVE answer to this question... Is it possible to make an SQL selection based on an order of possible condition values. Eg. Rows ID Type 2 Dog 2 Cat 4 Cat 5 Cat As you can see the IDs of the 1st 2 rows are the same. So I would like to select 1 row per group in order of preference, ther...

How to SUM from MySQL for every n record

I have a following result from query: +---------------+------+------+------+------+------+------+------+-------+ | order_main_id | S36 | S37 | S38 | S39 | S40 | S41 | S42 | total | +---------------+------+------+------+------+------+------+------+-------+ | 26 | 127 | 247 | 335 | 333 | 223 | 111 | 18 | 1394 | ...

How do i extract data from a DataTable?

I have a DataTable that is filled in from an SQL query to a local database, but i don't know how to extract data from it. Main method (in test program): static void Main(string[] args) { string connectionString = "server=localhost\\SQLExpress;database=master;integrated Security=SSPI;"; DataTable table = new DataTable("allProgram...

Force mysql to return no result on bit_or

I have a mysql query that uses bit_or on a result set. When there is no result set, the bit_or function returns 0 (this is correct as per the mysql documentation). For example: select n from t1 where a=1; Returns no rows. select bit_or(n) from t1 where a=1; Returns 0 I need to force the last query to instead return no result from...

GROUP BY and uniqueness in multiple columns

Lets say that I am looking to select 3 columns from a few joined tables: event_id, home_team, and the results of an aggregate function. The event_id is a primary key autoincremented. The home_team is not unique to every record in the table. I want to group by event_id to generate the aggregate function and then sort by the reuslts of...

how to set permissions for sql database?

I'm trying to host an asp.net website using iis 5.1 on my computer using xp pro. I'm using windows authentication in iis. Folder permissions for the site are set to allow authenticated users. Impersenation has been set to true in the web.config file. The website uses a local database which works just fine when accessed through VWD expr...

Multiple Condition Bulk Update in SQL & PHP

If I want to update a column value base on a condition I can just use the below query for a simpel +1 -1 case (translate into proper PHP call or ORM equivalent, of course): UPDATE articles SET STATUS = 0 WHERE STATUS = 1; But now the issue is that I want, based on the original the status, infer a new value of status from a dictionary...

Outer join problem in SQL Server

This is my query. And I want all rows of BF and matched rows of FT. It returns only 2 rows but the real row count is 135. How should I change my query? SELECT BF.FaturaNo, K.KlinikAdi, FT.teslimAlindi, FT.TeslimAciklama, FT.kurumTeslimAldi, FT.kurumTeslimAciklama, BF.basilmisFatura_id, K.klinik_id FROM BasilmisFatura...

SQL Rights Creator/Owner

Our software has data to store, so it also install MYSQL, a root user and a user with read only access if a third party compagny wants to install a backup solution for our data. But the third party wants to write data (a timestamp for backup purpose or something like that...) to another database. How can I change the user so it has read ...