DO NOT USE this for questions targeting Microsoft SQL Server, use the tag sql-server instead. "SQL" is an acronym for "Structured Query Language", it is used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. ...

learn more… | top users | synonyms (1)

0
votes
0answers
52 views

Why do non-integer joins in MYSQL take so long?

It seems that every time I try to run a query using a non-integer join in MYSQL, it destroys the speed of my queries. Is there a better way to join on text fields (especially ones that could be cast ...
0
votes
1answer
48 views

Linking Two database to execute join query

I have a remote odbc connexion and an MySQL database in my localhost i ask if there is a way to execute a join query ( linking the two database ) ? thanks.
1
vote
1answer
127 views

Checking if user owns child records (MySQL)

I am having a quite big problem with the following queries. The tables looks like: A (Parent) +------------+---------+ | id | user_id | value | +------------+---------+ | 1 | 20 | X | | 2 ...
1
vote
1answer
1k views

Impact on SSRS of migration of SQL Server from 2008 to 2012

As part of my project, we are upgrading SQL Server 2008 R2 to SQL Server 2012. We have a separate SSRS 2008 instance running on a separate machine which interact with these existing 2008 database ...
1
vote
1answer
28 views

Is it possible to find the user whose aggregated score reaches X value first?

Given this sample fiddle containing sales value and date for two users: http://sqlfiddle.com/#!2/8148be/3 How can I find the first user who has reached a total saleValue of 30 since the beginning of ...
0
votes
1answer
162 views

Very slow update with subquery (different tables)

I run this query to update "domains" table based on "log" table: UPDATE domains SET domains.mx_collected = 0 WHERE domains.domain IN (SELECT log.mail as domain_name FROM log WHERE `time` >= ...
0
votes
1answer
302 views

Query improvements without UNION

I have the following scenario. A users table, a records table and a memberships table. A user can be associated to zero or more records either directly with the records table records.user_id = ...
0
votes
0answers
23 views

SQL Server 2008 database is not coming online after restore.. Pleae need help asap

I have restored a 1TB database and now it shows the restore completed 100% but the database is not accessible. sp_who2 has a SPID 50 performing this restore but current command its showing is ...
0
votes
0answers
104 views

Find out profile creation date

Our DBA says that a specific profile was created but we cannot find out its name (and it wasn't provided by the DBA). We want to find out by looking at the profile creation date. How does one find ...
-1
votes
1answer
72 views

Show all categories from CATEGORIES table [closed]

I have these two tables, categories and files And I have this query that shows only one result/row. SELECT `categories`.`category_id`, `categories`.`timestamp`,`categories`.`name`, ...
1
vote
1answer
278 views

Is it possible to do flashback after truncate?

Is there any possibility of doing flashback after truncate ? Thank you in advance.
1
vote
4answers
6k views

TSQL command to delete backup files older than N hours

Can anyone please help me with a TSQL commmand to delete backup files older than N hours?
1
vote
1answer
9k views

Oracle XE 11g (ORA-12514: TNS:listener does not currently know of service requested in connect descriptor )

I have already seen the questioned in the stack overflow that might relate to my problem but let me emphasize that none of them could resolve my issue. issue is: when I wanted to integrate OWASP ...
2
votes
1answer
133 views

Select query - group by and sub group by

CREATE TABLE [dbo].[temptable] ( [Id] INT NOT NULL PRIMARY KEY IDENTITY, [uid] INT NOT NULL, [pid] INT NOT NULL, [event] INT NOT NULL, [timeStamp] DateTime NOT NULL ) I want ...
1
vote
3answers
1k views

I can't restore my database on SQL Server 2012. Exceeds size

I'm trying to restore a database from a .bak file. The file is only 89.3 mb large. I'm using the restore with replace option, so that all other data in the database is removed. We are just trying to ...
2
votes
2answers
130 views

My query fails to segment the results as intended. What am I doing wrong?

Update: Re-phrasing the question. Below are the results and the desired results. What do I need to do to get the desired results? See http://sqlfiddle.com/#!2/d0e13c/69 Thank you SELECT ...
1
vote
1answer
52 views

Order of output row in random order [duplicate]

When I do select query on single table then I get output rows ordered by primary key which is perfect, following query: select * from recondata where importid=131; but when I'm joining this table ...
2
votes
1answer
4k views

Writing a query to find all employee salaries that are higher than their managers

I have two tables with some dummy data. I need to find all employees that make more than their managers. I was led to believe the point of the exercise is to learn how to do subqueries. I can isolate ...
4
votes
1answer
3k views

How to remove known elements from a JSON[] array in PostgreSQL?

I'm facing an issue regarding using the JSON data type in PostgreSQL. I try to achieve storing a Java model denormalized in the DB. The model features lists of complex objects. Thus, I decided to ...
0
votes
1answer
5k views

How to calculate time difference in sql

I have one table named test. In that table I have a column named test_time of type DATE. I want to calculate the time difference between test_time and sysdate in minutes. select 1440 * ...
2
votes
2answers
283 views

Count where previous record exists in either of two tables

I'm trying to COUNT records on one table where both the counted records and their "previous" records exist either in the same table or on another. The table that I'm sampling has a composite PRIMARY ...
1
vote
3answers
440 views

Moved Model Database and now my SQL Server doesn't work

I moved my Model data and log files: ALTER DATABASE Model MODIFY FILE (NAME = 'modeldev', FILENAME = 'D:\Data\model.mdf') ALTER DATABASE Model MODIFY FILE (NAME = 'modellog', FILENAME = ...
2
votes
1answer
198 views

How to Substitute Variables in PostgreSQL

The given Oracle query inserts data into table by substituting variables. How I achieve the same in PostgreSQL? INSERT INTO control_threshold ( threshold_id, group_name, description, sql, ...
3
votes
2answers
268 views

PL/pgSQL fuction to find circular references

I have two tables ID Task 1 1 2 2 3 3 4 4 Col1 depend 2 3 2 4 3 1 4 2 ID and Col1 are related through FK constraint. I want to find out all circular references. Here ID ...
1
vote
1answer
2k views

Use limit with where clause in in mysql [closed]

I know where clause search and display the records as per criteria comes true, and limit is use to fetch the number of records from a table. But please help me when I am trying to use them both ...
0
votes
0answers
29 views

Enterprise system database strategy [duplicate]

Here is my current database design: Separated databases based on area of domain (Sales, HR, Accounting, Core such as login and menus, etc). Each database has a single service login, each with ...
0
votes
2answers
196 views

Is it possible to speed up this PARTITION BY query?

I've got a timeserie table. Each datapoint has also a statut field which indicates its providing source. I'd like to request last available datapoint as of date T but there could be several results, ...
2
votes
0answers
21 views

enable database to work with Snapshot Isolation [closed]

I can't enable snapshot isolation ALTER DATABASE mydb SET READ_COMMITTED_SNAPSHOT ON; ALTER DATABASE mydb SET ALLOW_SNAPSHOT_ISOLATION ON; query still 0 rows working 5 days and nothing ...
1
vote
0answers
186 views

Storing changes to stored procedure and triggers in PostgreSQL

I want a mechanism where I can store/track changes in stored procedure and triggers. I want to track these logs in some table. What is the best possible way ?
0
votes
1answer
150 views

Table Valued Parameter not pulling the correct data for my sp?

http://sqlfiddle.com/#!3/b2643/5/1 http://sqlfiddle.com/#!3/b2643/5/0 This link above has the sample database tables I created on SQLfiddle. I have 3 main tables in my stored procedure: ...
1
vote
1answer
44 views

How to maintain fixed number of rows per foreign key?

I would like to keep a record of the last N (say, 10) objects a user has viewed. I'm thinking a basic way to store this information might be the following table: CREATE TABLE history ( id ...
2
votes
1answer
143 views

Does Index Intersection work with Included Columns?

I've been asked by a report designer whether it is acceptable to add a new index to a table to speed up a particular report. The index would be on a single column, CreatedDate, but would have ...
2
votes
1answer
87 views

Replace consective numbers from a string

So if I have a table with values: Name ID ---- --- James 100 James 101 James 102 James 200 James 201 James 202 Alex 100 Alex 101 Alex 102 Alex 105 Alex 106 Alex 109 ...
0
votes
0answers
29 views

SQL Get result as a column

Is it possible to get a result as a column? The SELECT query will only need to return one record, however, at the time of querying the database it will not know what attributes are in the table, and ...
11
votes
1answer
822 views

How can I make a query to take a specific amount of time?

I am testing a monitoring application against a SQL Server 2000 instance. How can I write a T-SQL query that takes an amount of time that I specify? For example, most scripting languages have ...
0
votes
0answers
421 views

MySQL Update Default Value of Column in Multiple Tables From An Inner Select Statement

I posted this question on stack overflow, but his might be a better place for it. Reference: ...
-3
votes
1answer
6k views

What is the Difference between SQL Server 2008R2 and SQL Server 2014?

I want to take my project from sql server 2008 R2 to Sql Server 2014. But I want to learn what is T-Sql the difference between 2008 R2 and 2014 for Database Engine? I mean is there any end of life ...
1
vote
1answer
199 views

How to speed up looped INSERT INTO statements?

I currently use the following statement, for 10,000 rows it takes about 150 seconds. I tried removing the index on the target table, but this didn't help. Running the loop without the INSERT INTO ...
0
votes
0answers
36 views

Designing a database with Ints [duplicate]

Pretty much a newb when it comes to SQL Server. The question is, in 2014, should I be optimising my int columns - tinyint for status, smallint for fixed size lookups, int/bigint for transaction ...
1
vote
2answers
44 views

How can I set myself as owner of a database ? just using sql

As I want to view dependencies of just a couple of tables in my clients database I want to set myself as the owner of the database. If the database is called MyDatabase and my userName is ...
1
vote
1answer
131 views

Maintenance plan using external tool to execute query and stored procedures giving off no results

My situation is as follows: I am using a third party tool (VisualCron) to run stored procedures and sql queries on several database servers. The stored procedures are from http://ola.hallengren.com/ ...
-2
votes
1answer
438 views

How to restore a database from a .bak file to an existing database via GUI? [closed]

How can I restore a database from a .bak file to an existing database via the GUI instead of using the commands? Will the database be inconsistent if I restore a previous backup and what will happen ...
2
votes
1answer
102 views

Will adding more indexes speed up using RedGate SQL DATA compare?

We want to use RedGate's SQL Data Compare to migrate user data from one DB to a DB on a completely different provider. This will be a time-sensitive operation as we do not want our site offline for ...
3
votes
1answer
51 views

Safe to start Mirroring on Production Server?

We have a 350 Gig DB on SQL Server 2008. We intend to backup and restore it then immediately start mirroring. Is starting a mirror a dangerous operation to do on a production database ? Can I expect ...
0
votes
0answers
33 views

Trying to import an addressbook

I'm trying to import a .sql-file that I got by converting an .dbf-file. The problem is this line: INSERT INTO address values ('', '', 'Dekanat', '', 'Fachhochschule Hildesheim/Holzminden/Göttingen', ...
-2
votes
0answers
98 views

Cluster index or Partition in postgresql [closed]

I have a products table with 20,000,000+ and it's increasing. It takes alot of time to fetch a row from that table with that query select * from products where user_id = 1. So i made a partition on ...
4
votes
1answer
336 views

MySQL - GROUP_CONCAT returns duplicate data, can't use DISTINCT

I have a normalized database and I'm trying to return data from multiple tables using JOINs and GROUP_CONCAT. Problem: Rows are being duplicated with GROUP_CONCAT. I can't use DISTINCT because some ...
2
votes
4answers
107 views

Trigger or Stored Procedure?

Let's say I have two tables, foo and bar: CREATE TABLE foo( foo_id serial NOT NULL, count integer NULL, PRIMARY KEY(foo_id) ); CREATE TABLE bar( bar_id serial NOT ...
-1
votes
1answer
136 views

Backup and Restore Database Method

I have a production database. I am using FULL recovery model. I am taking regular FULL backup every week. I am planning to take LOG backup every day. Now, if my database crashes or failed to load due ...
2
votes
2answers
6k views

A transport-level error has occurred when sending the request to the server

In our Vb.net application(userd within a local network connection inside a office), which is used from long time now some of the users get the errors only sometimes a day A transport-level error ...