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)

1
vote
1answer
77 views

When is the index actually created?

I have noticed that even on huge tables with millions of records when I do a CREATE INDEX the index is created immediately (I get the console back in nsecs). Why is this? Doesn't it create the B-Tree ...
0
votes
2answers
146 views

high traffic mysql hosts

I'm wondering if any of you sql buffs out there have any suggestions for a high speed mySQL server. I need something that can handle roughly 33 updates and 33 queries per second, per user. and for ...
2
votes
0answers
26 views

optimizing a CTE Hierarchy [duplicate]

I have a table of accounts with a typical acct/parent account architecture to represent a hierarchy of accounts (SQL Server 2012). I created a VIEW using a CTE to hash out the hierarchy, and on the ...
0
votes
0answers
430 views

Alternatives for UPDATE statement Oracle 11g

I'm currently using Oracle 11g and let's say I have a table with the following columns (more or less) Table1 ID varchar(64) Status int(1) Transaction_date date tons of other columns And this ...
0
votes
0answers
587 views

Snapshot transaction throws random conflict. Should I choose something else? [closed]

I've got a problem with my transaction. Currently it runs in IsolationLevel.Snapshot. The action it does, can take some time depending on the amount of data, it has to import. What it does: Create ...
1
vote
1answer
551 views

Why DBCC CHECKDB is multiple times in error log

I have an issue with dbcc checkdb command . In the errorlog file I find the dbcc checkdb command multiple time within the interval of 30-45 minutes. I have scheduled a job which grep keyword error ...
0
votes
1answer
29 views

content types of insertion

I have a CSV file that contains a lot of integer values. Is it better to insert these individual values in bulk as in a full transaction or should I be inserting the CSV file itself into the MySQL?
2
votes
2answers
1k views

How to define alias in an ARRAY_AGG expression?

I'm trying to return pure JSON from a Postgres 9.2 table. SELECT ARRAY_TO_JSON(ARRAY_AGG(ALBUM_ROW)) FROM ( SELECT album, max(release_year) AS release_year, ...
0
votes
1answer
636 views

MySQL: Error while reverse engineering database from a sql file

I'm trying to reverse engineer a DB in MySql with a sql file generated from an OpenOffice database. while trying to import and run the sql file, I get the following error: ERROR: Line 1: syntax ...
1
vote
2answers
241 views

Databases: are there universal datatypes?

While designing database tables (using some tool like Enterprise Architect), how do I use only 'universal' datatypes that will work with all databases when I need to switch to a different database in ...
1
vote
3answers
178 views

Best practice to query administrative views for instance level elements

I want to query a monitor element at instance level (for example the memory used for the instance) via a query like this: SELECT MEMBER, MAX_MEMBER_MEM, CURRENT_MEMBER_MEM, PEAK_MEMBER_MEM FROM ...
-1
votes
1answer
113 views

how to update multiple records for single user in database? [closed]

I want to update multiple roles for user when admin update user roles I have table as follow user_roles username || role_name user1 | role1 user2 | role2 users username || ...
8
votes
3answers
61k views

SELECT DISTINCT on one column, while returning the other columns?

I have a query which uses three lookup tables to get all the information I need. I need to have DISTINCT values for one column, however I also need the rest of the data associated with it. My SQL ...
0
votes
1answer
40 views

Sorting by a field in child table

There are two tables: contract (with primary key contractid) and contractupdate (with field contractid referring to a contract). contractupdate also has DATE field startdate and TINYINT field day. I ...
0
votes
1answer
68 views

SQL - Referential integrity

seems like my problem pretty much describes GC (Garbage Collector) but I don't want to make a procedure to run every X time. so this is my question: I have three tables or more, refer to those as ...
2
votes
2answers
1k views

T-SQL - How to filter data from table

I'm new in DB world, so if you can help me it would be great. My problem: I have filtered some data and got a table with data, but need to filter them again. Picture might help you. For me, it is ...
1
vote
1answer
2k views

Select on several {name,value} pairs

I have a this schema: CREATE TABLE Pairs( id VARCHAR(8) NOT NULL ,name VARCHAR(40) NOT NULL ,value VARCHAR(1000) NOT NULL ,PRIMARY KEY (id,name)); I want to write a query to ...
1
vote
2answers
1k views

Delete rows from a large table with joins and aggregating (resulting in 1 % less rows in the big table)

I got a bit stuck on performance, so I thought about asking a bit of help. I have a working query, but unfortunatelly it feels rather slow and I know it's not as performant as it could be made ...
0
votes
1answer
2k views

Optimize MySQL Self JOIN Query

I have a query which is running in 15+ seconds SELECT t1.`ST_StockCode`, t2.`SM_StockCode`, t2.`ST_ItemSize` FROM `stocks` AS t1, `stocks` AS t2 WHERE ...
1
vote
1answer
215 views

Query_cache doesn't work with join

I have a simple join query, but for some reason query_cache won't cache it! SELECT id, news, approve, FIXED, DATE, allow_main FROM post LEFT JOIN post_plus ON post.id = post_plus.news_id WHERE ...
1
vote
1answer
245 views

.NET error when trying to create snapshot for transactional Replication

I encountered a bizarre prob today while creating a transactional publication on a SQL 2012 server running on Windows Server 2008R2. I had just had some success creating and initializing some Merge ...
1
vote
1answer
170 views

Help me convert SQL statement to MySQL

I have an application called Moodle version 1.9 and was migrated from Windows platform and Microsoft SQL Server to Linux and MySQL. Now, when I click save changes the SQL query statement from Custom ...
2
votes
2answers
341 views

What can be done to further enhance performance of Multiple Join and Aggregate Queries?

I have a typical star schema simulated here, and I am mentioning two queries: first query simply joins the fact table with 2 dimension tables and 1 calendar table, and the second query joins and ...
0
votes
0answers
76 views

Is there a syntax to access the table name in the select query?

In MYSQL. I want to select the records which has the same contents with the table name. for example, consider the following table. <TABLE : tbl_1> +-------+------+ | id | no | ...
0
votes
1answer
117 views

Insert a group of consistent item with foreign key but colliding with existing items

Is there a way to insert a group of items that are dependent but consistent between them with unique primary keys and foreign keys but that are colliding with items in database. For example, given a ...
2
votes
3answers
1k views

How to DROP multiple tables from databases?

I have situation where someone mistakenly execute script for creating tables under wrong database. Let's say we have database DB1 which is some test database, and we have to create other database ...
0
votes
1answer
1k views

Query: select all rooms which are not booked

I have a simple room booking system consisting of following tables: booking | id | user | begin | end | room | id | name | booking_map | id | room_id | I can list all rooms that are booked at ...
2
votes
1answer
49 views

Order results from query to have a certain result at the top

I'm not sure there is even a way to do this, but thought I would ask anyway. I have the following example output from a query: Name Country Number -------------------------- Harry Germany ...
1
vote
1answer
224 views

How to find what prevented in getting a lock?

Sometimes my update statements fail after 3000 milliseconds with 'Lock request time out period exceeded' error. That 3000 limit is coming from my application through SET LOCK_TIMEOUT 3000 setting, ...
-1
votes
1answer
53 views

Relation that combines entries with their subsequent entries, in order of date

I need to come up with a query that can do the following: I have a table with a bunch of transaction records, whose attributes are not important, other than the attribute Date. I need to come up ...
6
votes
1answer
351 views

Minimal Logging Conditions in SQL

I have written a script to test out the claims made on this page http://technet.microsoft.com/en-us/library/dd425070(v=sql.100).aspx in the table titled Summarizing Minimal Logging Conditions about ...
4
votes
1answer
85 views

Query uses Primary Key Index instead of Nonclustered index defined

I have this simple query and I am confused why the index is not working. SELECT lop.RecordID ProspectusID, c.c_code CourseCode, c.c_desc CourseDescription, COALESCE(c.c_major, '') ...
1
vote
4answers
339 views

Which of these queries is best for performance?

Which of these queries are best for performance ? Sometimes I wonder if SHORT scripts really is the best thing to focus on. These scripts performs the same task. With left joins i can achieve what i ...
0
votes
1answer
376 views

Party Relationship Model in Practice - Insertions

I'm moving this question for StackOverflow in hopes to get perspective from a more database-oriented community. Here is a basic representation of what I'm doing (in pseudo sql): Parties - ID, ...
0
votes
0answers
193 views

My queries are slow under load

I am performing a load test for my application. All my SQL queries which are fired from my application, individually look better and perform fast. The same SQL are becoming bottleneck when they are ...
0
votes
0answers
69 views

All databases restoring in Suspect Mode in SQL Server 2012

I've just re-installed SQL Server 2012 (removed the evaluation copy and installed a licenced version) and now every database I try to restore, it fails to completely restore and the database sits in ...
1
vote
2answers
32k views

Error: Specified cast is not valid. (SqlManagerUI)

I am trying to restore database created on server to my localbox however i am getting 'Error: Specified cast is not valid. (SqlManagerUI)' error message. Server Info: Windows Server 2008 Standard ...
18
votes
2answers
3k views

Index not making execution faster, and in some cases is slowing down the query. Why is it so?

I was experimenting with indexes to speed up things, but in case of a join, the index is not improving the query execution time and in some cases it is slowing things down. The query to create test ...
1
vote
1answer
178 views

creating 2 database at the same time in db2

Do you know whether it is safe to have in one shell user db2inst1 creating a database A and having another shell the same user creating at the same time database B? create database A # shell 1 ...
1
vote
0answers
96 views

MySQL: What criteria should I base my table column order/arrangement/grouping on?

Does the order, arrangement or grouping of columns with large (such as long text descriptions) and small (such as bit and tinyint) field types have any noticeable impact on MySQL (InnoDB engine) ...
1
vote
2answers
3k views

mysql: using comma-separated values

I have a simple mysql table which I use as a server booking system. A user can log in to a server, if he has a valid booking for that server. A sample data might look like this: ...
0
votes
0answers
115 views

SQL Server JOIN with COUNT [closed]

I have two tables I'm trying to query across. One contains an entry for every time a user tunes to a particular channel in our middleware. The second is normalized table containing station ...
3
votes
5answers
6k views

Mirroring vs. Log Shipping

The software company I work for is planning to migrating our infrastructure into the cloud. Our current focus is to find the best database replication method. Current Servers: SQL Server 2008 SE - ...
2
votes
0answers
1k views

Query optimization on a large table in PostgreSQL

I am not super experienced with databases, just have a college level course under my belt. I am trying to see if an existing query can be optimized. Currently on average takes over 300ms. There is a ...
5
votes
1answer
13k views

Syntax of INNER JOIN nested inside OUTER JOIN vs. query results

TLDR; If you look at the 2 execution plans, is there an easy answer to which is better? I purposefully did NOT create indexes so it's easier to see what's happening. Following up on my previous ...
1
vote
3answers
170 views

How to create implicit select statements

I need to create an implicit select statement for each table with all of its coluns - i.e. SELECT COL1, COL2, COL3 FROM TABLE1 instead of SELECT * FROM TABLE1. There are too many tables to use the ...
3
votes
1answer
101 views

Restoring with replace going incredibly quickly [duplicate]

So I have a database (on a SQL Server 2008 R2 SP2 instance) that is 2TB uncompressed, with a .bak file that is 500GB compressed. As I have been toying with the fastest way to restore this database ...
1
vote
2answers
111 views

SQL Server 2000 optimzation job hasn't run for a while

Our SQL Server 2000 used to run a Sunday morning 3am job of optimizing the database. Somehow it was turned off and hasn't run in a year. We have noticed slow access to the database. We turned it ...
0
votes
1answer
852 views

Calculating time spent on query cache lock

How can I calculate the total time my MySQL database is spending Waiting for query cache lock ? I've found two specific very simple tables that adding a SQL_NO_CACHE drastically improved the ...
2
votes
1answer
2k views

Return ResultSet with column names from postgresql Stored procedures

I have the following postgresql Function: CREATE OR REPLACE FUNCTION readMessage(messageFor INT, qid INT = NULL, ctxt INT = NULL, messageFrom INT = NULL, byTimeStamp BOOLEAN = FALSE) RETURNS SETOF ...