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)

1
vote
1answer
3k views

Retrieving data from inner join using LIMIT and OFFSET

These are my two tables: table1 qid[PK] |gid[PK] |abcd | xyz | date ---------------+---------+---------+------+------------ 00001 | qwe | 54 | a | 1994-11-29 00002 ...
1
vote
1answer
152 views

Setting up simple relational database structure

I'd like to set up simple MySQL database but I'm a bit confused about everything, so let me try to explain... I have 4 relevant tables, let's call them POS, POS_STRUCT, POS_STRUCT_DIV and MEMBERS. ...
2
votes
1answer
250 views

sorting groups of related rows by average values while keeping the groups together

I'm using PostgreSQL 8.4, but would like a standard SQL solution if possible. Consider the following table. corrmodel=# SELECT * from data limit 1; id | datasubgroup_id | datafile_id | ...
1
vote
1answer
465 views

Find who will change a record in oracle DB

Someone is updating a record in a custom Oracle table, is there a way to find who is updating the record and or at least the table?
0
votes
1answer
155 views

How to create an index view?

I have a view which is doing summation of several columns: Select cola, colb, cola + colb + colc from table tbl_a Can I know what are the indexes I should create for the view to improve its ...
1
vote
3answers
162 views

Efficient SQL database design for recording examples of a word

I am designing a dictionary-like program which stores (and displays) a few example sentences of the given word. One way to design a SQL database for such problem is to create a table with two columns ...
1
vote
1answer
2k views

Possible Causes of a Slow Sql View When Filtered

I have a view in Sql Server 2008 that when performing just a: SELECT * FROM [Table] Will return roughly 40000 rows by 130 columns. Here are 6 runs with client statistics on (roughly 7 seconds ...
1
vote
2answers
6k views

Select multiple rows from one row based on column values

I have a product table where the value of two columns can imply either one or two actual product results. If column X = 1 AND Y = 0 return one result, if X = 0 and Y = 1 return one result, if X = 1 ...
1
vote
1answer
313 views

How to re-arrange rows to best fit within groups?

I categorized a table with the method introduced here to categorize my items to folders with a limit size of 100. mixing_order id num_items cat order_in_cat cumulative_sum folder 1 ...
1
vote
1answer
682 views

Sql Server rollback to some point in time

This seems like a fairly common scenario, yet I'm not sure how to do this. I have a very large database (think a lot of terabytes), which makes it impossible to create a full backup. At some point, I ...
1
vote
3answers
2k views

How do I use SSMS to compare Database 1 Table 1 against Database 2 Table 1?

I have two database - Database1 and Database2. Both database contain a table that have similar structure as follows: ...
2
votes
1answer
439 views

Parsing and binding variables for SELECT .. WHERE column IN ( .. ) queries

I'm looking to make sure that all queries in a php web application have proper use of bind variables to minimize parsing of the queries. I'm wondering how Oracle parses queries that compares a ...
1
vote
1answer
235 views

Group activities in activity feed by users and products

On my website I'm building an activity feed where I got the basics done and are now making some improvements here and there. One of them is the grouping. I've built it so that if multiple users buys ...
1
vote
1answer
5k views

How to check for null in column? and use other column instead?

How would I write a query that involves the following check: if colA is null then colB = colB1 + colB2 if colA is not null then colB = colA
2
votes
2answers
1k views

How can I capture queries that fail on the SQL Server due to connection failures?

How can I capture queries that fail on the SQL Server due to connection failures? Profiler doesnt seem to capture if there is a connectivity loss. This is scenario: DB server running in Domain A ...
1
vote
0answers
969 views

SQL query optimization in Prestashop e-Commerce solution

I'm working on a layered navigation module within Prestashop e-Commerce solution. I'm trying to optimize a SQL query which creates a temp table during execution. I think this is creating a ...
3
votes
1answer
739 views

Right Trimming Binary Data in SQL Server

Scenario: I am inserting a string into a binary field (CONTEXT_INFO) and then later attempting to pull it out and convert it back to a string. When I do, the resulting string has a length of 128 ...
0
votes
1answer
712 views

Massive update to Clob fields oracle 10g

I need to remove a string of characters from 2000+ clobs fields in oracle 10g. How would I do this in PL/SQL? For example, in table t1 there is a clob field called VBase that needs to have the ...
1
vote
2answers
464 views

Database Design - One table from many source(One to One)

I have a 'Text' table, the text table may came from different source, like Tweet, SMS, Email, etc. and each source have their own log, and Text is came from the source. so i came with some solution, ...
1
vote
1answer
1k views

Attach database failed for Server '{SERVER_NAME}\{INSTANCE_NAME}'. (Microsoft.SqlServer.Smo)

Strange, I tried to attach the database AdventureWorks from this site - http://sqlserversamples.codeplex.com/ However, I encounter the following problem while attaching AdventureWorks2008R2_Data.mdf ...
1
vote
2answers
4k views

Multiple triggers vs a single trigger [closed]

Scenario: Each time data is inserted/updated/deleted into/in/from a table, multiple unrelated items of business logic need to be executed. Question Given that the solution is to use database ...
4
votes
1answer
2k views
1
vote
0answers
62 views

Oracle update query sequence of actions on DB side

I searched online but could not find particularly consolidated source of what happens when you execute an update query. I know that there are a few actions happening like create redo data and logs ...
0
votes
1answer
244 views

How do you reset the master key in sql server 2005?

Our old DB admin is gone, any ideas? It looks it was set up many years ago.
2
votes
2answers
2k views

Sp_helptext Error

I am using sp_helptext to list some stored procs instead of going through the ui. I am having a problem with the naming convention we have chosen to adopt. I have a stored proc nameed [Test.FooBar]. ...
5
votes
2answers
4k views

Correct way to design a shopping cart websites database

I am in a web applications course. My instructor really didn't like the layout of my database, saying it was incorrect in pretty much every way. Fast forward 2 months when I'm remaking the website in ...
1
vote
1answer
100 views

T-SQL Case functionality

Is it possible to structure a CASE statement as follows? For each Path column I want to update the Value column, but the values aren't being set and I'm not sure how to proceed. The columns are all ...
4
votes
1answer
754 views

Removing duplicates from a query with conditions in Access 2007

I have a table of transactions with 880,095 records that I am querying. There are duplicate Transaction ID's in the table that I would like hidden/removed when querying the table. Eg 1. ...
0
votes
1answer
172 views

How to number SQL results sequentially?

Given following query - SELECT name, age FROM students WHERE age > 22 The result is - name age ---- --- Kshitiz 23 Steve 22 Paul 24 How can I number the results sequentially? Like ...
4
votes
1answer
337 views

Large Transaction Log Backups in Service Broker-enabled system

We have a system that uses Service Broker for asynchronous messaging, with a fairly high throughput of messages. We don't really care about the persistent features of SSB in this scenario -- the ...
13
votes
5answers
2k views

Sequential GUID or bigint for 'huge' database table PK

I know this type of question comes up a lot, but I've yet to read any compelling arguments to help me make this decision. Please bear with me! I have a huge database - it grows by about 10,000,000 ...
1
vote
1answer
623 views

Restore .mdf data file for a File Group in SQL Server

I have a database with three filegroups and each filegroup hosting one datafile. One of the secondary filegroups XYZ with data file xyz.ndf got updated with wrong/bad information in various tables ...
1
vote
2answers
1k views

Changing field length when foreign keys reference primary key field in table

I have a situation where a number of foreign keys are referencing a column in Table "A". I would like to change the length of the column in table "A". What is the best way to accomplish this in SQL ...
0
votes
0answers
30 views

Max connections sql server express could have? [duplicate]

Possible Duplicate: Max connections SQL Server Express could have? I have sql server 2005 express edition installed on one of my client's machine, and lots of other users are also connected ...
5
votes
2answers
843 views

Deleting duplicate records when using text datatype

I have a large (~678,000 rows) table storing emails, and I need to delete duplicate records that match the fields of the email: to, from, subject, body, as well as the foreign key record_id. Normally ...
5
votes
3answers
939 views

“AT TIME ZONE” with zone name PostgreSQL bug?

I was answering this stackoverflow question and found strange result: select * from pg_timezone_names where name = 'Europe/Berlin' ; name | abbrev | utc_offset | is_dst ...
2
votes
3answers
4k views

Which SQL Server Express edition is right for me?

I have developed a Java program which works with SQL Server as it's database. I have installed SQL Server 2012 Enterprise edition on my Windows and designed the database via SQL Server Management ...
3
votes
2answers
243 views

Inner Join or direct data save in SQL Server

I am developing a social network site and expecting very good response from people so expecting huge users (maybe more than million in years). My website is holding user information table and all its ...
2
votes
3answers
562 views

How to select data in a sub query only once?

I have the following query: SELECT ordno from orders where ordno NOT IN (SELECT ordno FROM invoices) There are about 25000 records in each table. I have indexed the ordno column. The query ...
4
votes
2answers
2k views

How do you set the pagesize, codeset and table space when creating a database in DB2?

I want to create a database in DB2. I found some information on this page I want to use only some options which are explained on the page: PAGESIZE CODESET TABLESPACE Then, I want to ...
-1
votes
2answers
389 views

Oracle SQL Query/SubQuery Single column with mutilple data [closed]

Id File-Name Descrption 1 yyyy Started 2 yyyy incompleted 3 rrrr Started 4 tttt started 5 uuuu started 6 rrrr completed 7 tttt completed 8 uuuu ...
3
votes
1answer
79 views

a query that shows the load request received through GPRS by salesman

I have mobile sales system, in which the salesman sends their stock request in handheld device and through GPRS the data comes to MS SQL database. I need o show a report that shows the which request ...
13
votes
2answers
335 views

Does firing off an indefinite WAITFOR increase the log file size?

In the last release of my app, I added a command that tells it to wait when something arrives in the Service Broker queue: WAITFOR (RECEIVE CONVERT(int, message_body) AS Message FROM MyQueue) The ...
0
votes
2answers
651 views

how to select * from XML where id=1?

declare @xml xml, declare @num int set @num = 1 set @xml = ' <row> <Id>1</Id> <name>reza</name> </row> <row> <Id>2</Id> ...
2
votes
1answer
7k views

Multiple “GROUP_CONCAT”s with WHERE clause

In a table as id name type info 1 BMW car yes 2 Reno car no 3 IBM electronics no 4 Sony electronics yes 5 Mazda ...
8
votes
1answer
4k views

Deadlock error isn't returning the deadlock SQL

Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. I am getting this error randomly when one of my ...
5
votes
1answer
163 views

Practical application of EXISTS vs. LEFT JOIN to find addresses for delivery

Our end users have many ways of shipping product to our customers. They can use the customer address in one table ([customer]), a specific delivery address in another ([dropship]), or yet another ...
4
votes
1answer
450 views

database design issue

This is my first time on this beautiful content rich site. I have a sql server 2008 database, but am not too experienced with good relational database design. My project is this: I have a school ...
0
votes
2answers
693 views

How to mix pairs of rows without JOIN (in a temporary table)?

I have a TEMPORARY table containing pairs of key/value as id col1 col2 type pair 1 key1 key2 key 1 2 value1 value2 value 1 3 key3 ...
3
votes
2answers
184 views

Query taking too much time

My query is taking too much time to execute. Please help me here. mysql> explain select pcm.catalog_id from cat_produ_catal_map_defer pcm, cat_catal_catal_map_defer ccm, cat_catal_defer c ...