An acronym for "Structured Query Language" (it's not the name of a specific DBMS product), SQL can be used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. It can also be used to manage schemas and data ...

learn more… | top users | synonyms (1)

3
votes
0answers
268 views

To NULL or not to NULL? [duplicate]

Possible Duplicate: Why shouldn't we allow NULLs? I've heard that it's a bad idea to do database design such that nullable fields exist. However, eliminating nullables often cause much ...
0
votes
1answer
149 views

Add parent_id dynamically based on another field

I have a version table using a field to track order: id, owner_id, order, version 5, 1, 1, 1.1 6, 1, 4, 1.2 7, 1, 7, 1.2.1 8, 1, 10, 1.3 I want to ALTER TABLE version ADD COLUMN parent_id and have ...
1
vote
1answer
364 views

What is SQL/PSM and how does it differ from other versions of SQL?

I have searched SQL/PSM and I have learned that it stands for 'Structured Query Language/Persistent Stored Modules', but what I want to understand is what that really is and how it differs from T-SQL ...
2
votes
3answers
5k views

What are the causes and solutions for mutating table errors?

I understand mutating table errors are caused by a design flaw or problematic query. An old query was recently put into production which throws a mutating table error. Our DBA solved the problem but ...
4
votes
2answers
2k views

DB2: Error when using NOT EXISTS with SYSIBM.DUAL in a batch query

I have data in a java object as data1, data2. data1 and data2 together forms a composite key in myTable where I want to insert the object. The writing is happening as a batch. Like 10 insert ...
18
votes
5answers
776 views

Should Query Tuning be Proactive or Reactive?

As a software developer and an aspiring DBA, I try to encorporate best practices when I design my SQL Server databases (99% of the time my software sits on top of SQL Server). I make the best ...
3
votes
3answers
3k views

How? SQL Cluster with multiple active nodes (not failover)

I'm building a new SQL 2008 R2 (Enterprise) Cluster that is backed by an EqualLogic iSCSI SAN. Instead of building a failover cluster (which I have done), I would instead like to setup several nodes ...
5
votes
3answers
822 views

Indexing - Uniqueidentifier Foreign Key or Intermediary mapping table?

Looking for some expert views on this guys - I'm not a DBA by trade so would appreciate any advice. Comments on the rest of the schema aren't required as it is purely fabricated to illustrate my ...
9
votes
2answers
2k views

Updating 700 million rows to same value

I've got a data warehouse (oracle) where I need to set a column to the same value for all 700 million rows. I don't have admin access, or access to an admin, so this needs to be accomplished with ...
0
votes
3answers
2k views

Figuring out database timezone

Does anybody know of a way to alter a time zone on a SQL database? Is there any tool that could find the objects using the date and time?
3
votes
2answers
1k views

Can the sorting from an ORDER BY statement be saved explicitly with only one UPDATE statement?

I have this table: SELECT * FROM items id | item | position ---|-----------|---------- 1 | USB cable | 0 2 | SD card | 4 3 | Mouse | 2 4 | Keyboard | 0 5 ...
5
votes
6answers
493 views

Check if DISTINCT is really necessary

I have a query in mysql as follows. SELECT DISTINCT `tableA`.`ColA`, `tableA`.`ColB`, `tableB`.`ColA`, ... FROM `tableA` LEFT JOIN `tableB` ON `tableA`.`colC` = `tableB`.`colA` WHERE ...
9
votes
3answers
12k views

Notification on long-running query or deadlock in SQL Server 2008 R2?

I'd like to know if there is a way to send a notification on deadlock? If so what queries would be required. I understand that SQL Server takes care of deadlocks, I simply would like information on ...
2
votes
2answers
408 views

Full Name search query

We currently have a solution for this in production, but it's pretty bad. I'd like a fresh perspective on it please. We have a PERSON table with an ID, LAST_NAME, FIRST_NAME, MIDDLE_NAME, and ...
4
votes
1answer
509 views

T-sql: Select most specific match from table

Apologies for the horrible title. I couldn't come up with a better way to briefly describe the problem. Here's the scenario: Users can set up service instructions to be attached to a work order ...
2
votes
1answer
4k views

How to display a number with fixed number of digits before the decimal?

I am looking for result 0123.56 and the following query should have worked. SQL> select to_number(123.56,'0999.99') from dual; select to_number(123.56,'0999.99') from dual * ERROR ...
4
votes
1answer
5k views

oracle format specifiers: to_number vs to_char

SQL> select TO_NUMBER(123.56,'999.9') from dual; select TO_NUMBER(123.56,'999.9') from dual * ERROR at line 1: ORA-01722: invalid number SQL> select TO_CHAR(123.56,'999.9') ...
4
votes
5answers
552 views

EXISTS clause in SQL

I have following requirement: main_set table has all the ids, user_input table has all user entered ids. I want result of ids that exist in user_input table. If nothing in user_input table then I ...
1
vote
1answer
241 views

Optimising a sql correlated subquery statement

I am updating a column on tableA with data from tableB like this: update tableA set bKey = select bKey from tableB B where B.colB = tableA.colB bKey has a unique index on tableB. Which is the ...
9
votes
3answers
304 views

Query Performance Tuning

When you finish writing a query/stored proc/function, what's the most informative way to quickly get some performance parameters? Do you run the query and view the actual execution plan? If so, what ...
1
vote
4answers
270 views

Is there a DBMS that allows the “= NULL” syntax?

Inspired by a StackOverflow question (Why doesn't SQL support "= null" instead of "is null"?). Is there a DBMS that actually supports the = NULL syntax?
2
votes
3answers
271 views

Non-deterministic aggregated result

Why is my query non-deterministic? I have query that do the following: select sum(float1*float2*coalesce(float3,1)) from table When I run this query I get a deterministic result, but it seems not ...
4
votes
0answers
156 views

Which SQL datatypes exist since when and in which RDBMS? [closed]

I found a general comparision of different SQL implementations that only covers some data types (BOOLEAN and TIMESTAMP) and a comparision of datat type support in different RDBMS from 2009 that does ...
5
votes
5answers
773 views

Advice with date column SQL Server 2005

I have two datetime columns in SQL Server 2005 that I need to query without the time portion of the datetime. Currently, my query looks something resembling this (just an example): WITH Dates AS ( ...
4
votes
1answer
676 views

How to get text for default language

I have so tables: and so data at Language table: and so data at Text table: I have to return text for requested language if it exists and text for default language if it does not exist. Is it ...
4
votes
3answers
352 views

Database Design Issues

My question consists of three parts: When can I be sure that my database design is perfect? Is returning to the database design to change some issues (i.e, adding new column, deleting a column, ...
3
votes
2answers
2k views

PostgreSQL: Using schema and table names from other tables?

Consider the situation where I have all my schema names in one table and all my table names in another table. Is it possible to do something like in the following? SELECT value FROM (SELECT ...
8
votes
3answers
679 views

overstating field size in database design

I have some fields for my tables that are strings and at the moment, most of the field size have pretty high character limits. For instance, 100 char for the street name. Is there a penalty for using ...
2
votes
2answers
1k views

How do I group results in batches of consecutive rows with the same 'module'

I'm looking for a seemingly very simple SELECT. I have a logging table LOGGING of which three columns are of interest to me: MODULE (text), PDATE (date), PTEXT (text). Actually, I care only about ...
4
votes
2answers
1k views

Estimate average and median efficiently in Postgres?

I have a Postgres database with tables in the billion scale. So any aggregate functions such as count() and avg(), as well as "order by random()" are very time consuming. Postgres has pg_catalog which ...
6
votes
4answers
242 views

Which SQL standard is most broadly and completely supported?

I want to concentrate on one of the SQL language specs for learning and reference purposes. Which version of the SQL standard is most broadly supported across DBMS'es so that I can focus my time and ...
2
votes
3answers
1k views

when selecting from multiple tables I get a multiplication of the records

When executing this query below it takes too long. And the result is too much records, more than possibly in the database. The query should return around 117.000 records. That is the amount of ...
1
vote
3answers
58 views

SQL Server - Index Including PK

Lets assume we have a table as follows: PK -- nonclustered primary key Col1 -- unique clustered Col2 Col3 Is this index: nonclustered index on (Col2, Col3) any different from this index: ...
0
votes
1answer
2k views

Minimum user rights for connecting MS Sql database remotedly

I have followed this tutorial for getting connected to a Microsoft SQL Server. I connect with ping functionality of Glassfish Server and thus I have to give some user rights to be able to even ping ...
3
votes
1answer
133 views

In which form Microsoft SQL password should be given when creating a user?

I am creating a Microsoft SQL server user with the guidance of this MSDN article and giving the system the following commands: CREATE LOGIN MyName WITH PASSWORD = 'MyPass'; USE My$DatabaseName; ...
3
votes
3answers
641 views

Improving slow queries. Slow query log attached

Below is the Slow Query Log when my .NET application was running. Please let me know how to improve the performance of the queries: TCP Port: 3306, Named Pipe: (null) Time Id Command ...
1
vote
1answer
66 views

SQL query question

I want to find the records of August birthdays in own table.I'm using Datetime Field. Sample record: 01.08.2001 06.06.1985 26.08.1995 etc.. How should I do write a query? Regards,
3
votes
1answer
296 views

SQL Server CTE problem

This question is in reference to my last question: SQL Server 08: Union over while I'm writing a CTE to do what was described in that question (find available time slots over a given number of days. ...
-6
votes
1answer
1k views

How do I convert this Access query for SQL Server? [closed]

I have a Query used in Access which does not work in SQL Server as it stands: SELECT mstPatient.PatientID, mstPatient.PatientID AS PKNO, ...
2
votes
1answer
347 views

SQL Server 08: Union over while

I've done some reading on this, and I keep seeing people say it's a bad idea, but hear me out! I have a stored procedure which needs to find a series of timeslots over a number of days. Due to the ...
21
votes
3answers
4k views

Performance difference for COALESCE versus ISNULL?

I've seen a lot of people use the COALESCE function in place of ISNULL. From internet searches, I've found that COALESCE is ANSI standard, so there is an advantage that we know what to expect when ...
12
votes
1answer
810 views

What does collation mean in database parlance?

I am learning sqlite from a book which has mentioned collation and collating sequence multiple times. What does it mean exactly in the database world ?
1
vote
1answer
425 views

IS_SRVROLEMEMBER returning NULL for valid non windows user

I have a service that executes a stored procedure to query the db for results. The stored procedure needs to use impersonation on the user who is logged in the client (since the service has its own ...
4
votes
2answers
904 views

Best way to evenly distribute data over partitioned tables

I am working with a database with roughly around 500MM records. We currently use a static partitioning method that partitions the data by an int identifier such at < 150MM goes on partition 1, > ...
2
votes
2answers
170 views

MySQL Query Optimization : Bets and Averages

I have the following selection string: SELECT * , AVG( `q1` ) AS betavg, COUNT( bet_id ) AS nr, MAX( q1 ) AS qmax, (MAX( q1 ) - AVG( `q1` )) AS diff FROM jos_bet_1x3_best GROUP BY `bet_id` HAVING ( ...
1
vote
1answer
109 views

I need help migrating data through databases

i've a web page with some data about the users. Recently I made a complete change and start developing a new portal and of course a new DB structure. My question is what's the best way to migrate my ...
7
votes
3answers
4k views

How to Best Implement nearest neighbour search in mysql?

So, in short, What should be the data type of latitude and longitude? What SQL command I should call to get the first 100 nearest restaurants for example? Detail: I have 100k biz record each with ...
4
votes
3answers
1k views

MySQL Query Optimization : Indexing and Pagination

I'm adding pagination to my 'latest news' php script and running in to an issue. SELECT sid, title, time, bodytext, author, url FROM news WHERE approved=1 ORDER BY time desc LIMIT $start, $limit I ...
2
votes
2answers
555 views

Slow Query logging everything

I have a mysql instance that is logging slow queries. I have it set to 1 sec, but I am getting back lots of these:(example) Query_time: 0.000237 Lock_time: 0.000064 Rows_sent: 0 Rows_examined: ...
3
votes
1answer
463 views

A question on MySQL SELECT Algorithm/Function

Let's say I have 100,000 rows in a table, and each of the rows has a boolean value. Only ten of these rows have a value of 1, the rest are 0. How would MySQL perform a SELECT on only the rows with a ...