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)

7
votes
1answer
668 views

Friends relations in MySQL

I'm developing a friendship relation in MySQL where friend relation is mutual. If A is friend of B, then B is friend of A. If one of the users end friendship then relation drops. I want to learn which ...
2
votes
2answers
1k views

EXECUTE sp_executesql

i have a problem with EXECUTE sp_executesql and stuck with it. my query is as follows DECLARE @TABLE_NAME VARCHAR(5)='#T' DECLARE @TABLE_ID INTEGER=0 DECLARE @QRY NVARCHAR(MAX) ='' ...
2
votes
1answer
506 views

Should I use left join to do my job in this scenario?

What I want to do is to find out the items which appeared more than once in this table: mysql> desc tables; +-----------------+---------------------+------+-----+---------+-------+ | Field ...
2
votes
1answer
528 views

Renaming the Data Sets in SSRS

What is the easier way to rename the Data Sets in completed SSRS report? I have created a report in BIDS 2008 and now for some reasons I have to rename the Data Set names, but it seems that renaming ...
1
vote
1answer
399 views

How do I query based on percentages of a subset of values?

I have a table with a column named Type that can have some set of values. For instance, A, B, C, D, etc. Behind the scenes this is mapped to an Enum. I need to query this table to get a percentage ...
4
votes
4answers
9k views

How to list all views in SQL in PostgreSQL?

How do I list all views for a database using an SQL command in PostgreSQL? I would like something similar to output of the psql \dv command, but preferably just a list of view names. e.g., SELECT ...
1
vote
3answers
2k views

Workarounds for setting default schema for domain group?

I am currently working on a project for a client, they have asked me to change the database from Oracle to SQL Server. So we migrated the database across to SQL Server 2008, when this was migrated ...
1
vote
1answer
8k views

“Operand type clash” with DATE column

I enter the following command into the SQL Server Management Studio insert into testtable ([product_name], [price], [expire_date], [expire_time]) values ('Teapot', 10.00, 23/12/2012, '12:35:00') ...
4
votes
4answers
889 views

Shrink database is not shrinking as much as expected on a 1.5 TB database.

I'm working in an Enterprise system with a 1.5 terabyte database that is on a single filegroup, with the log in Simple Recovery Mode. Since we have many teams working on different projects in ...
12
votes
2answers
2k views

PostgreSQL procedural languages - differences between PL/pgSQL and SQL

Can anybody please summarize the differences between: http://www.postgresql.org/docs/9.1/static/xfunc-sql.html and http://www.postgresql.org/docs/9.1/static/plpgsql.html ? Main points: ...
3
votes
2answers
316 views

Query for fetching records from SQLite database on Blackberry

I want to fetch data from SQLite database for Blackberry. There is one table with four columns: ID, FROM, TO, TIME I want to fetch record on the basis of FROM, and TO values. Where condition 1: ...
3
votes
2answers
845 views

Restarting One Database Not Entire Server

Is there anyway to restart one database in SQL Server instead of restarting the entire server? I have a task in perpetual rollback on one of my databases. I'd like to restart it without turning off ...
6
votes
2answers
324 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 ...
8
votes
4answers
1k views

How to check if a subquery has exactly one distinct result and a specified value concisely?

I found myself writing the following: select 'yes' where exists(select * from foo where val=1) and not exists(select * from foo where val<>1); and wondering if there is a more concise way ...
10
votes
3answers
2k views

Database starts always in recovery mode

Everytime I restart my server, the database is always in recovery mode, and it takes about 20 minutes for it to behave as normal. This always and only happens when I restart the server, so I have a ...
2
votes
1answer
81 views

Response On Database Failover

Let say, that I have principal server named P, and mirror server named M. I've got 7 databases that are in server P, and 7 mirror databases on server M. Whole engine works fine when we are talking ...
1
vote
1answer
2k views

How to design a table for storing news items?

I have a script that can get result from news websites and it will run every hour. The php script will get the title and content. The things I want to store in MySQL are: title content ...
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 , ...
4
votes
1answer
686 views

Store SSRS Report export directly to database

As a requirement, I have to check for a certain condition on some data in the database, if the condition is true, then I have to create a pdf report and store it on a table. I have everything set up ...
3
votes
1answer
275 views

SQL Server 2008 SP1 to SQL Server 2008 R2 upgrade

One of our project is planning to upgrade from SQL Server 2008 SP1 to SQL Server 2008 R2. I would like to know from this community the suggestions on: Is there any configuration or any change ...
-1
votes
1answer
222 views

Selecting just one table from Oracle view [closed]

I am creating a view to ease my manual selecting because I only want to fetch data from DB where it is meeting certain criteria which are present in several tables, so it is containing a lot of joins. ...
11
votes
4answers
3k views

Is it possible to increase query performance on a narrow table with millions of rows?

I have a query that is currently taking an average of 2500ms to complete. My table is very narrow, but there are 44 million rows. What options do I have to improve performance, or is this as good as ...
3
votes
1answer
58 views

INDEX on a table where I'm only filtering on a row_number()

I've got the following table (scaled down to a MWE): Fiddle here. CREATE TABLE weekly ( yearnum int, weeknum int, location varchar2(5), weekly_count int, weekly_sum int); INSERT INTO weekly ...
3
votes
2answers
250 views

SQL Server Transaction Log Initial Data Load

What is the standard process when initially populating a database with 5GB+ to avoid a large transaction log? From my understanding the log file would jump to a large size after the initial load and ...
1
vote
0answers
139 views

hStmt/cursor error caused by faulty data?

Could a busy hStmt and invalid cursor errors be caused by faulty data? ODBC and the software that connects to the database is correct and working - i have ran a test with a clean database (that has ...
3
votes
1answer
550 views

Connecting to an SQL server instance without using square brackets to avoid backslash

In our company we have an old piece of software which was written by our previous I.T manager but was never finished. The program connects to SQL server but we want it to point to a newer SQL server ...
3
votes
2answers
4k views

How to GROUP_CONCAT DISTINCT values in a MySQL query that gets number of records and min/max values?

I'm running MySQL 5.0.88 (Coldfusion8) I have a product search which I'm querying number-of-results as well as min/max prices/rebates across the product table. I also want to include a string of ...
2
votes
3answers
295 views

selecting multiple instances of a record based on record lifespan over years

I have a table of items that have a origin date and a life span. I want to create a procedure that selects all of the items that will need to be replaced in a specific duration. I feel like there is a ...
2
votes
2answers
186 views

remote connection

Im trying to connect to a remote sql server using windows authenication. I'm using visual studio 2012 and going to a remote sql server 2012. I have already checked in sql studio that it is set up for ...
10
votes
2answers
477 views

Postgres query plan of a UDF invocation written in pgpsql

It's possible when using the pgadmin or plsql to get a hold of a query plan for a sql statement executed via a UDF (using EXPLAIN). So, how do I get a hold of the query plan for a particular ...
11
votes
3answers
1k views

Use MySQL to regularly do multi-way joins on 100+ GB tables?

Background: I’ve created a web application that I would like to be able to scale reasonably well. I know I'm not Google or Twitter, but my app uses a fairly large amount of data for each user and thus ...
2
votes
3answers
9k views

“lock request time out period exceeded” Error When Trying to See DB Hierarchies

I'm having problems with a database. I can run basic queries, albeit much slower than normal. When I attempt to view the hierarchy trees for tables, views, or procedures in SSMS Object Explorer, I ...
2
votes
1answer
918 views

Can't Restore DB Because of Active Connections

I have a DB I would like to restore. There are other active connections on the DB. I tried using sp_who2 to find those connections and manually kill them. Unfortunately, this did not solve the ...
2
votes
2answers
306 views

Cross Apply without a function

I would like to run a query very similar to this on one of my production databases: -- Setup the table (Already there in my real scenario) create table dbo.MyTable(MyValue int, MyGroup varchar(5)) ...
1
vote
1answer
442 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?
3
votes
1answer
1k views

How do you connect to SQL Server 2008 Express when SA is disabled?

I'm trying to create a database in SQL Server 2008 Express (as installed by Visual Studio) but I don't seem to have any permissions to do so. There must be a way to do this, or there would be no point ...
1
vote
1answer
187 views

Querying multiple tables

I am working on a query from our ticketing system, and I am having problems figuring out the best way to join these tables together. I have the following tables/fields: SR_service: stores ticket ...
7
votes
1answer
199 views

Is it possible to limit the maximum disk usage for a user

Is it possible to set a limit on the amount of physical disk space a user (or group of users) can use within a single database? For example is there some method of associating a schema with a ...
0
votes
1answer
1k views

Database Mail Issue

I am getting a strange error randomly when i try to send emails using database mail using SQL Server. The mail could not be sent to the recipients because of the mail server failure.Exception ...
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 ...
1
vote
3answers
319 views

MySQL Query - How to get most recent demographics?

I have a table that has duplicated cardnbr's. I need to pull out demographics that are the most recently used by the customer. I have a date field (lastvisit) that shows their most recently used card. ...
0
votes
3answers
118 views

How to convert query results into groups of common results

I have a query that returns results like this: MyValue MyGroup _______________|_______________ 56 | I _______________|_______________ 12 | I ...
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 ...
1
vote
1answer
167 views

Get and count all blog posts and all users that fits a LIKE condition (two sepparated queries)

I've this tables: -- -- Table structure for table `default_cmvblog` -- CREATE TABLE IF NOT EXISTS `default_cmvblog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(100) COLLATE ...
2
votes
2answers
2k views

Querying a database efficiently for a huge chunk of data

Here is my query SELECT * FROM ( SELECT a.*, rownum rnum FROM ( SELECT id, data FROM t ORDER BY id ) a ...
5
votes
2answers
311 views

Correlated subquery and join: still the same exectution plan?

I have a correlated subquery like this (from BOL): SELECT DISTINCT c.LastName, c.FirstName, e.BusinessEntityID FROM Person.Person AS c JOIN HumanResources.Employee AS e ON e.BusinessEntityID = ...
3
votes
2answers
1k views

Sub-query executes 1 time for a parent query or more?

If i apply a static data in where clause is it faster then applying a sub-query. Example: (The query returns 5 records as a result set) SELECT STARTDATE, ENDDATE FROM TEST WHERE STARTDATE = ...
0
votes
2answers
1k views

xp_cmdshell bcp wont save file

EXEC xp_cmdshell 'bcp "SELECT lastconnectip FROM RF_USER.dbo.tbl_UserAccount" queryout "C:\test.txt" -T -c' The command above runs, the output: NULL Starting copy... 1000 rows successfully ...
9
votes
4answers
3k views

Benefits of using backtick (`) in MySQL queries?

In MySQL we can create queries with or without the backtick (`) symbol. Example: SELECT * FROM TEST; SELECT * FROM `TEST`; Both works fine in mysql-console. Is there any technical difference ...
3
votes
4answers
6k views

What's better/faster? MySql or FileSystem?

Let's imagine a web site that is a directory of people. For each person there may be a profile photo and a biography. I'll admit my SQL queries could be better but in general what would be faster and ...