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
0answers
131 views

Use of hash functions in group by?

I'd use a listagg() to generate a list of components a certain customer has and compare it to another list generated the same way somewhere else to detect inconsistencies. The problem is that ...
2
votes
1answer
433 views

Oracle sequence generation performance during persists of large data sets

In the context of an Oracle sequence, when persisting > 200 million records, is there a performance hit on the database if the sequence cache is the default value of 10000? That is to say does ...
2
votes
0answers
460 views

SQLite Performance Tuning

I have the following query, which fetches data from only one table. It is a query which is supposed to return data for an autocomplete function. Autocomplete data can be in text1 or text2. The ...
0
votes
0answers
210 views

How do I get the date that each user last logged onto the server / database in SQL Server 2005

Currently, I have the following code that gets the DBNAME, USERNAME, ROLE_NAME for each user on the database. I need to get the last logged in date for each user to fill in the LASTLOGIN_DATE. ALTER ...
2
votes
4answers
157 views

SELECT Statements only please

I have a user that wants to use SQL Server Management Studio (SSMS) to run SELECT statements. I don't want him to be able to modify data. I can't regulate his permissions through Windows ...
3
votes
2answers
1k views

Unable to disable SQL statement logging in PostgreSQL 9.1

I am running PostgreSQL 9.1 on Windows Server 2008 R2. I enabled SQL statement logging to the stderr log by modifying my postgresql.conf file, but now I can't seem to disable the logging without ...
1
vote
3answers
130 views

Query missing one date; only happened today

This should be pretty reproducible I hope. I'm on Oracle 11g. This query, which I use as part of another query, is acting strangely: SELECT TRUNC(SYSDATE - ROWNUM) DATEITEM ...
1
vote
1answer
303 views

The best way to log access to SSRS reports

We have a number of SSRS reports created using BIDS 2008 on SQL Server 2008 r2. The business wants us to log access to these reports. For example who and when run the Report A. What is the best way ...
1
vote
1answer
108 views

How to get non-deleted messages for one user_id if the same user_id appears in two tables at same time?

I'm trying to get non-deleted (deleted = 0) messages for one user_id if the same user_id appears in two tables at same time, but something is wrong because I am not getting the correct or expected ...
1
vote
1answer
926 views

Trying to Build TreeView Query in T-SQL

I have parent records in two tables, Table1 and Table2. Some records in Table3 are children of Table1, and some are children of Table2. I would like to build a query that I can use to populate a ...
2
votes
1answer
89 views

What are the effects of GRANT DELETE?

What is the difference between: GRANT DELETE ON TABLE1 TO ROLE1 and GRANT DELETE TO ROLE1 One of our DBAs executed the second version by mistake. I want to be certain I understand all the ...
3
votes
2answers
755 views

Deprecating SQL Server, need to redirect clients to new server

I am in the process of deprecating an old SQL Server server and replace it with a new server. My old SQL Server is a named instance called: SQL\Development My new SQL Server is a default instance ...
4
votes
1answer
293 views

SQL Server 2008: use AVG() and an inner join

Here's what I have so far. I know this works, but I need to get the average of the pulse and depressionlevel instead of returning actual values for each row: SELECT Patients.LastName , ...
2
votes
0answers
540 views

SQL fulltext accent insensitive

I am using SQL Server fulltext containstable and the column which is indexed has collation Czech_CS_AS, so why when I have word "byt" it returns records with word "být" too. I thought that the ...
2
votes
1answer
914 views

SQL Query - Set Date Variable by Table/Column Reference

How do I set the @DATE variable by using a table/column reference? Right now I've set it manually as you can see below with the opening: SET @DATE = '2012-03-31 01:00:00'; The table from which I ...
1
vote
1answer
407 views

Merge 2 tables and fetch data one by one

I have two tables: product & offers. products has (prod_id, category_id, prod_name, brand, price, status) offers has (offer_id, prod_id, offer_type, discount_amt, validity) I want to display ...
3
votes
3answers
4k views

Alternative query to this (avoid DISTINCT)

Note: I work with MSSQL 2008, but I guess it's valid for many others DB engines I have this table "Users": UserID User CountryID 1 user 1 1 2 user 2 2 3 user 3 3 4 user ...
1
vote
1answer
1k views

Production SQL Server High CPU for a Single Query

I have a single query which is consuming a larger amount of CPU than I would expect in SQL 2008. I am not able to determine why the CPU is spiking for this single query. I can trigger an ...
4
votes
2answers
329 views

Database design for part-number generator

Crossposted to Stack Overflow: Database design for part-number generator I'm working on a generator for part numbers, where each space will have a meaning and each space will have a number of ...
3
votes
1answer
113 views

Slow MySQL query, not sure why

I'm working with an intranet application for property tax collection, and I've hit a snag. The following view runs much slower than I'd expect: create or replace view propertytaxessub0 as select ...
1
vote
2answers
6k views

How to Export SQL Server Database To A File For Later Import To Different Computer

I'm using the Sql Server 2012 Import and Export data (64) i'm not sure what options i should be picking to do what i want. I just want to be able to export all the data in the database to a file which ...
1
vote
2answers
4k views

Sql Server agent can not start

I can not start Sql Server agent to create job. Can anyone help me? . I'm using Windows 7 Ultimate , Sql server 2008 Rc2 See this images:
6
votes
2answers
325 views

Is it worth partitioning a Table by single value in Oracle?

Normally, if you have a column you frequently query a table by, you ought to stick an index on it. But is it worth also partitioning a table by this column, if all possible values are known in ...
2
votes
3answers
735 views

Find and remove gaps in sequence across two different columns

I've tried to solve this problem using a set-based approach. However, since I need to look at each row I think I must use a cursor; please correct me if I'm wrong. The table: Project, item, method, ...
1
vote
3answers
567 views

Restoring an entire SQL Server database instance

I have a server that we will be completely reformatting then rebuilding. Everything will be rebuilt exactly as it is now - same filenames, same directories, etc. After SQL Server is installed, I ...
4
votes
2answers
1k views

Updating rows conditionally with a gapless ascending value

A user has a table they would like to update. Depending on the data in other columns they want a particular column to be updated with an ascending value starting from 1 that is gap-less. The rows ...
2
votes
1answer
737 views

Find which numbers in [1, 161] are not in the result set?

How to find which two number in [1, 161] is not in the result set? Can I find this two numbers using sql command? mysql> select blog_id from wp_blogs; ... | 149 | | 150 | | 151 | | ...
1
vote
1answer
3k views

execute() vs executeQuery() in MySQL Connector C++

With MySQL Connector C++, I can use the sql::Statement::execute() function if I am going to modify the database (INSERT, UPDATE, DELETE, MERGE), or the sql::Statement::executeQuery() function if I am ...
2
votes
1answer
531 views

Oracle With Statement and Delete Together

I am trying to use WITH statement and DELETE together. But I get ORA-00928 error. Basically my code is like following WITH TO_DELETE AS ( SELECT TableKey FROM SOME_TABLE WHERE SomeConditions LIKE ...
1
vote
3answers
526 views

Compare two tables amount with respect to priortization of FundType

I have two tables one is PaymentDetail and another is Ledger Here i want to prioritize paymodetype in manner that cash should be considered first for R,A and then I FundType, then Credit Card, ...
2
votes
1answer
1k views

How do I persist recurring events?

I've been tasked with designing a system to recur events. Events may recur daily, hourly, monthly or yearly. Users should be able to schedule events "every 3rd Wednesday of the month" or "The 1st of ...
2
votes
1answer
1k views

change encoding of database from latin1_swedish_ci to utf8

I have an huge database in latin1_swedish_ci. Now i need to convert all data to utf8 collation. My question is about the consistency of the information. When I do this change it is possible corrupt ...
1
vote
1answer
228 views

query optimization delete nested query [closed]

Can the following query be optimized ? DELETE FROM COLOR_TAGS WHERE COLOR_PROJECTID = $id AND NoteID IN( SELECT ID FROM note_note WHERE BibID=$bid AND isdel=0);
2
votes
1answer
2k views

Why Is oracle ignoring my index?

This query is not too complex: select trunc(created_date, 'MONTH') as created_date, al.op_name, al.region, al.alarm_type, COUNT(1) as total_new, SUM( (SELECT ...
2
votes
2answers
587 views

Tracking of deleted records who delete the transaction in SQL server 2008r2

how can we check who deleted the transaction even after few days in sql server 2008 r2 is there any command instead of logs
4
votes
2answers
25k views

How do I use the IF…ELSE condition in a WHERE clause?

I'm attempting to use the IF...ELSE construct in my WHERE clause to selectively apply conditions to my SELECT. Should this work? CREATE OR REPLACE package body If_Else_Pack IS PROCEDURE Moving ...
5
votes
1answer
1k views

Mysql sub query returns more than 1 row

SELECT * FROM wp_posts WHERE ID IN ( (SELECT courses FROM wp_category WHERE CatID =401) OR (SELECT meta_value FROM wp_postmeta WHERE post_id IN (SELECT courses FROM wp_category WHERE CatID =401) ...
1
vote
2answers
747 views

SQL Partioning on date, how does it work for future records?

I am setting up a new system and I would like to partition the data for speed. Basically what I would like to do is have one database with all the latest information (e.g. last 3 months). then have ...
4
votes
1answer
130 views

According to the SQL92 spec, can I store the value 1 in a field where the precision = scale?

Is it SQL92 compliant to store the number 1 in a field that is defined as NUMERIC 3,3? What about DECIMAL 3,3? Does this mean that the precision is a floating decimal place or static that must ...
2
votes
1answer
786 views

MySQL: AVG of defined variable per month

I need help with the following code: SELECT DISTINCT userid , count( userid ) as login_count FROM ( SELECT DISTINCT userid , ...
3
votes
1answer
511 views

Retrieving queries when the hour of starting timestamp is less than the hour of ending timestamp

I have a CTE-based query in which I retrieve hourly intervals between two given timestamps. My query works as following: Getting start and end datetimes (let's say 07-13-2011 10:21:09 and 07-31-2011 ...
7
votes
3answers
5k 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 ...
2
votes
1answer
91 views

Count total where owner_user_id = some_value and deleted_by_owner = 0 or to_user_id = some_value and deleted_by_to = 0

I didn't know if this is possible using just a query or if I need some procedural logic on this one. I have this table: CREATE TABLE `default_messages_users` ( `id` int(11) NOT NULL ...
2
votes
1answer
104 views

Question about new behavior of current connection combobox in SQL Server 2012

I have a question about the new behavior of the database selection combobox in SQL Server 2012 (Press Ctrl + U to move your focus to it). It seems that, unlike in SQL Server 2008 R2, clicking in the ...
1
vote
1answer
692 views

T-SQL, show a set of rows (specific column) as a field, for a better desc, please see the table relationship

I have been having a problem for quite a while now, that I can show with a sample of 5 tables (I'm actually dealing with more than 5!): -------------------------------- shipments ...
1
vote
2answers
389 views

Managing features for a real estate agency [duplicate]

I have a database table real_estate where the basic information is held (id, status, sku, address, building_type, sales_status) and now I want to attach features to that real_estate table. The data ...
0
votes
1answer
524 views

MySQL table with multiple values in one field

I'm building a database for a real estate company. The real estate properties are managed by sales people using a CodeIgniter website. How should I proceed with the database design for this table? ...
-1
votes
1answer
492 views

Very slow MySQL query. Index problem?

I have a query like this: SELECT BE.NAME as NAME, BE.PREVIEW_TEXT as PREVIEW_TEXT, BE.ID as ID, FPV1.VALUE as PROPERTY_COUNTRY_VALUE, FPV1.ID as PROPERTY_COUNTRY_VALUE_ID, ...
1
vote
2answers
251 views

Join on clustered tables shows greater cost than non-clustered tables?

I have created a cluster and have two tables emp and sep on the cluster. When I do the simple query... explain plan select * from emp_cluster join dep_cluster using (dno) the cost is 26. I ...
2
votes
2answers
3k views

Remove the last character from Variable String

I have a few variable data in the column "email". For example: roy2087@gmail.com123 sg123@yahoo.compori How do I get rid of the characters after .com? I used Replace(email,'.com%',gmail.com), ...