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
4answers
38 views

Are all matching indexes (indices) searched for a query?

If I have multiple indexes that include a common attribute - will each index be searched upon a query involving this attribute? Or is only one index searched?
0
votes
2answers
200 views

Partitioning MySQL for “expired” transactions to improve performance

I am dealing with an existing application that uses the database as a sort of transaction log in several cases, for example orders or payments. These tables are large (20 - 60 million rows) and poorly ...
-2
votes
3answers
182 views

Left Join not giving desired result

I have two Datasets FEES PAYMENTS CrsCode InstNo FEE Regno CRSCODE Instno Payment CA1 -2 100 R1 CA1 -2 100 CA1 -1 200 ...
2
votes
1answer
947 views

Reorganize full text catalog is offline or online?

I need to schedule a Full Text Search Maintenance and I was reading this link: http://msdn.microsoft.com/en-us/library/ms176095.aspx. Reading this documentation I am supposing that I need to ...
3
votes
1answer
84 views

Scheduled stored procedure on all databases in my server

On SQL Server 2012 (not express edition) I'd like to schedule the execution of a stored procedure every hour. On the same server I have lot of databases with the same structure, and I'm constantly ...
0
votes
2answers
180 views

Using a keywords table with multiple other tables

Using MySQL I need help determining how to model a Keywords table to three different tables (Products, Certifications, and Exams) - I have included my model which is using what I refer to as ...
-1
votes
1answer
358 views

How to merge data from 2 databases [duplicate]

I have a SQL-Server database that crashed while I was away on vacation. All info from 5/2/13 is missing from our current database because my replacement implemented a back-up of the database from ...
0
votes
1answer
158 views

PostgreSQL created a PostgreSQL user on mac. Is this necessary?

I just installed PostgreSQL on a Mac (Mountain Lion) today. The installer created a mac user PostgreSQL on my machine. After installation, the user still exists. My question is that why postgreSQL ...
1
vote
1answer
542 views

How do I refresh SQL server cross database references after a database is reattached with a different name? (Are there hidden synonyms?)

I have 2 seperate SQL databases on the same SQL instance. Database1 references tables on Database2 in its views and stored procedures. Everything was working fine until we had to create a fresh ...
0
votes
3answers
4k views

How to find all positions of a string within another string

How can I find all the positions with patindex in a table or variable? declare @name nvarchar(max) set @name ='ali reza dar yek shabe barani ba yek ' + 'dokhtare khoshkel be disco raft va ali ...
4
votes
1answer
207 views

How to view the full, flattened query underlying a Postgresql view?

If I have a view on a view on a view (etc.), is there a way to show the full query that this expands/flattens to?
1
vote
1answer
292 views

SQL Index order and performance based on cardinality and data

I've been working quite a bit on a query that's not operating very efficiently on a DB2 database. The thing will return up to 30k rows or so and take up to 10 seconds. I've been working on getting ...
7
votes
1answer
1k views

LATCH_EX Waits on Resource METADATA_SEQUENCE_GENERATOR

We have a process that generates an inventory report. On the client side, the process splits of a configurable number of worker threads to build a chunk of data for the report that corresponds to one ...
0
votes
1answer
53 views

Get Maximum Value

I am using MS Access database. I have a table (Proposal) with the following properties: ProposalID - PK, Title, RequestedAmount, ResearcherID - FK I want to run an SQL query to get the candidate that ...
0
votes
1answer
92 views

Hash in SQL query

I saw few sql queries with ### appended before and after column name in where clause like `select a from emp where a.###id### = 1` What is significance of these hashes?
1
vote
2answers
107 views

Saving a SQL Server database to a file and opening it on another server under any database name

I am trying to find an efficient way of being able to physically save and open a SQL Server database like how it's done with Access. I would like to be able to save my entire database into a file ...
0
votes
1answer
1k views

Query that ranks students order by marks and give the position of student even when there are students with equal marks

I need an sql that will rank students order by marks scored in a specific examtyp e.g CAT1 and give exact position even if the students have equal marks e.g in this sample data admNo 2525 and admNo ...
-2
votes
2answers
2k views

Export complete database to a remote server including (Tables, Stored Procedures, Triggers)

How do we "export" a complete Microsoft SQL server database from one server to a "remote" server (including all the "stored procedures" and "triggers"). The export facility provided in the management ...
1
vote
2answers
111 views

How to backup databases to ensure data recovery

I have 15 customer databases that have minimum replication at different sites. I currently do nightly back-ups and transfer the database back-up nightly to our main server via 7zip. We recently had ...
-4
votes
1answer
225 views

Update date Column values? any please help? [closed]

I Want to copy and data in same Table and Update date Column values? any please help?
1
vote
1answer
159 views

weak entity with a many to many relationship with its owner

I have a database that keeps track of the hours worked by a contractor per week. I have one table for contractors that contains "con ID" as primary key. The other table Weekly Hours Tracker contains ...
1
vote
2answers
113 views

Is it possible to validate DML statements?

Suppose that I want to delete a user named 'abc cba' from the database. So I run the following query: DELETE FROM table WHERE fname = 'abc' AND last name = 'cba'; commit; Now, there can be more ...
2
votes
4answers
2k views

Two-sided UNIQUE INDEX for two columns

Creating a table with composite PRIMARY KEY or using UNIQUE INDEX for two columns guarantee uniqueness of col1, col2. Is there a tricky approach to make the reverse order of two columns UNIQUE too ...
-1
votes
1answer
100 views

Why is this mysql query wrong? [closed]

I try to run the following sql query in mysql SET @rank:=0; WITH TEMP ( SELECT @rank := @rank + 1 AS ROW_ID , UUID() as RANDOM_VALUE,D.* FROM house_information_new D ORDER BY ...
1
vote
1answer
886 views

Using a Having clause with an outer join

I want to use a "having" clause with an outer join, using a column that is used in the outer join. This is my query: SELECT I.CARD_BIN BIN FROM GE_ICA_BIN I LEFT OUTER JOIN GE_PAYEE_VALIDATION ...
2
votes
1answer
103 views

Backing up SQL Server 2008 database in different recovery model

We currently have a production environment with 10 SQL Server 2008 databases in Full recovery mode (for obvious reasons). We back these databases up fully at a frequent interval, but due to the Full ...
0
votes
1answer
76 views

“Replicate” sql structure between testing and staging on same database instance

On my local development server I have a database set up which gets hooked into Entity-Framework and is then used for unit testing. Let's call it COMPANY\Database On the same server (and same database ...
1
vote
3answers
296 views

Same query taking 0.2 sec in Oracle database but 4 mins in SQL Server

SELECT A.Field1 FROM Table1 A INNER JOIN Table1 B ON A.Field2 = B.Field2 AND A.Field3 = B.Field3 AND A.Field4 = B.Field4 AND B.Field1 = "string1" AND B.Field2 = "string2" AND A.Field5 = (SELECT ...
2
votes
1answer
786 views

Trigger doesn't run when value of a column changes from null to 1

I have this trigger: delimiter $$ create trigger tr after update on t1 for each row begin if new.col1 !=old.col1 then update t2 set col2 =1 where t2.col3=t1.col3; end if; end $$ This ...
-6
votes
2answers
453 views

Challenge: Build MySQL table that's not in first normal form [closed]

I have read numerous books and articles about database design and SQL in which it is said that a database should be in first normal form (1NF). (Some then go on to describe situations in which it may ...
0
votes
2answers
392 views

Using MySQL InnoDB as an Archive

My site has a main MySQL InnoDB table that it does most of its work on. New rows get inserted at a rate of 1 million per week, and rows older than a week gets moved over to an archive table on a daily ...
2
votes
1answer
5k views

Select first row (grouping) + add aggregate function

First have a look at this question on StackOverflow. I'm looking to accomplish the same task, except I also need to add an aggregate function (PostGIS's ST_Union) to my query. How can I combine the ...
1
vote
1answer
132 views

Can I use Try_Cast to give me a query result column with different datatypes?

I have a column that is varchar(max). It contains mostly valid XML. But sometimes it has invalid xml (that I still need). I am trying to make a view for this table that allows the value to display ...
2
votes
2answers
150 views

What can I do to make mysql use the expected indices?

What can I do to make mysql use the expected indices? I've got 4 tables, two containing resources, and the others containing historical changes. One pair uses indexes correctly, the other doesn't, ...
3
votes
0answers
299 views

SELECT COL_NAME(969262708, ORDINAL_POSITION) returns a NULL value in one of the rows

So I've got a Stored Procedure that's copying data from one table to another. It calls this other SP to get the column names. I didn't write this darn thing, but here's that part: ALTER PROCEDURE ...
6
votes
1answer
321 views

Landed as BI, but databases are a big WTF, what to do?

Maybe a duplicate, but I believe my case is a bit different. From one of the answers I got to this post on SQL Server Central that also comes handy too but is not quite the same scenario: 9 Things to ...
1
vote
2answers
439 views

Challenge. Split database 500 records in two smaller datasets, randomly

I have a database with 500 records. I want to split these records to 75% and 25% *randomly*in order to use the different datasets for training and testing to machine learning algorithms. Does anyone ...
1
vote
1answer
107 views

Big jump in search time for Postgres Index query for results with high selectivity

I am doing some performance comparison of databases and lucene for full-text searching. So I use Postgres to create an Index for the data to search: CREATE INDEX bodies_index ON bodies USING gin ...
1
vote
4answers
15k views

Retrieving row count without using Count function

I wrote a query below which shoots me a syntax error why would it do so, SELECT MAX('Row') FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) 'Row' FROM USERS) Error Desc: Incorrect syntax near ...
2
votes
1answer
682 views

Restoring SQL Server 2012 database onto 2008

I am trying to restore a SQL Server 2012 database after I set the compatibility level to SQL Server 2008 by following the instructions as listed on: ...
0
votes
4answers
3k views

Database Restore Failed Due to Incompatible Version of SQL Server [duplicate]

I am working on different two SQL Server , I need to transfer database from one server to another but problem is both server has different version. Below is Image of Error message. Using SELECT ...
1
vote
0answers
58 views

MySQL not using resources?

Hi I have a decent setup: 16Gb RAM and a 4 cored CPU. I'm on a 64-bit Windows OS with MySQL Ver 14.14 Distrib 5.5.24 Win64 (x86). I am also using InnoDB. The query I am using to test the setup is a ...
3
votes
1answer
747 views

Create SQL Script for Statistics

I wanna create script my whole table, including all statistics and indexes. In SSM, When I right click table and create script, it gives me script for Indexes for not for statistics. If I right ...
1
vote
1answer
208 views

Separating tables vs having one table

At the moment I have a table setup that looks somewhat like this: create table tbl_locationcollections ( id int(11) PRIMARY KEY IDENTITY, --(Primary Key), name varchar(100) not null, ...
-1
votes
3answers
115 views

Add Contents in a Column and make them 0 [closed]

http://sqlfiddle.com/#!3/96f11/3 In the above fiddle, I need the required output in the Fiddle. ie., The UserID column in Filtered Table and Main table are equal. I need to get the Amt column data ...
4
votes
2answers
807 views

How to sync a database with an external full text engine?

How do you keep your external full-text engine (Lucene, Solr, etc) in sync with your database data? For example, keeping track of inserts, deletes, updates. My current solution involves a big union ...
4
votes
1answer
1k views

Postgres: count(*) vs count(id)

I saw in the documentation the difference between count(*) and count(pk). I had been using count(pk) (where pk is a SERIAL PRIMARY KEY) not knowing about the existence of count(*). My question is ...
3
votes
2answers
4k views

Creating a PostgreSQL SERIAL column using pgAdmin3

When I use pgAdmin3 to create a column of type serial, why does it instead create nextval('prices_id_seq'::regclass)? Should we keep this type defined by pgAdmin? Manually create the table with SQL ...
1
vote
1answer
70 views

Summation query with complex grouping criteria

I have a database of coded actions with this structure. {User, Date, ActionCode} I need to generate reports based on dates and action codes, and the action codes are not clean because we have to ...
4
votes
2answers
9k views

Extract part of string based on nth instance of character

I am trying to find a way to extract part of the strings below. I need everything between the 6th and 7th \ character. \\fileServerA\d$\LiteSpeed\Wednesday\ServerA\Tlog\DBA1_TLOG_20110504_0333.SLS ...