An acronym for "Structured Query Language", 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 access privileges.
1
vote
2answers
79 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
58 views
Complicated join with where clause
I have four tables:
sales
sales_thumbs
sales_images
sales_sizes
sales table:
+--------------+---------------------+------+-----+---------+----------------+
| Field | Type | ...
0
votes
1answer
66 views
Want to Get Brands In Wordpress Database Structure Saved as Custom Post types
I am having difficulty in fetching the brands per category in the sidebar of my website.
Here is the description:
I am using the feeds and feed uploader to upload feeds and create brands and product ...
0
votes
1answer
47 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 ...
1
vote
2answers
96 views
Search every column in every table in Sybase Database
I'm been taxed with the task of creating an application that pulls data from our Micros Point of Sales system. The POS is using a Sybase database running on one of our servers. The database schema is ...
-2
votes
2answers
72 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
68 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
47 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
68 views
The job failed. The owner (pc\user) of job FULL DB BACKUP does not have server access
SQL Server 2008R2 is failing to execute log backup hourly.
Date 5/2/2013 10:22:19 PM Log Job History (LOG BACKUP)
Step ID 0 Server pc Job Name LOG BACKUP Step
...
1
vote
1answer
33 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 ...
4
votes
2answers
7k views
Oracle: Quick way to list all database links
The title says it all, is there a way to quickly list all the current database links in oracle?
Something along the same lines as this, which lists the current user's tables:
select * from ...
1
vote
2answers
48 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
566 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
49 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
56 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 ...
1
vote
3answers
52 views
Transfer data from DB2 to Oracle
I want to transfer data from an old DB2 system to a new Oracle database.
How should I go about doing this?
0
votes
0answers
15 views
Range query from month and year [migrated]
I have a table like this:
ID month year content
1 4 2013 xxxxx
2 5 2013 yyyyy
3 6 2013 zzzzz
4 8 2014 fffff
I want to query it based on a year ...
2
votes
1answer
67 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
19 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
226 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 ...
0
votes
1answer
40 views
Find Underlying Data Type (int - integer) of Oracle Table instead of number
I can create an example table using following syntax.
CREATE TABLE "TABLE2" (
"COLUMN_INT" INT NOT NULL,
"COLUMN_INTEGER" INTEGER NOT NULL,
"COLUMN_SMALLINT" SMALLINT NOT NULL,
...
2
votes
1answer
39 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 ...
0
votes
2answers
106 views
How can I simplify this query?
I have written the following SQLite query:
SELECT sum(amount) / (julianday('now', '+1 day') - julianday('2012-08-11')) * 14 AS 'Cost Per Fortnight'
FROM
(
SELECT "transaction".transamount AS ...
-5
votes
2answers
126 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
3answers
48 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 ...
0
votes
1answer
62 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 ...
0
votes
0answers
11 views
Vote to a db server using session key
I do not know if this is the right stackexchange site to ask this question, but I believe that is relevant.
I am trying to implement an e-voting protocol. At some point the protocol says that server 1 ...
2
votes
2answers
99 views
How can I improve my table design for different types of an entity?
Consider an accounting system as an example. I have an Entity called Client. Client can be of different types, with different fields applicable to different types. I consider creating separate tables ...
0
votes
1answer
143 views
FETCH API_CURSOR causing open transaction in tempDB
A select statement run from Oracle 11gR1 to SQL Server 2005 using Gateway leaves an open transaction in tempdb. The user is a datareader in Database XYZ. Not sure why the open tran is in tempDB when ...
1
vote
1answer
52 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 ...
5
votes
6answers
2k views
Get the rank of a user in a score table
I have a very simple MySQL table where I save highscores. It looks like that:
Id Name Score
So far so good. The question is: How do I get what's a users rank?
For example, I have a users ...
2
votes
2answers
43 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
41 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
180 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 ...
4
votes
3answers
19k views
Oracle SQL - CASE in a WHERE clause
Is it possible to somehow do this?
WITH T1 AS
(
SELECT 1 AS SEQ, 'NOTHING 1' AS SOME_TYPE FROM DUAL UNION ALL
SELECT 2 AS SEQ, 'NOTHING 2' AS SOME_TYPE FROM DUAL UNION ALL
SELECT 3 AS SEQ, ...
3
votes
1answer
913 views
Postgres PgAdmin III Query Builder crash
I've been using Postgres and pgAdmin III for some years, but this morning I had a very BIG BIG problem.
I'm using pgAdmin III 9.0 on Windows Xp operating system, on my laptop Dell Latitude E4300.
...
0
votes
0answers
15 views
How to get Greenplum table defintion?
There are already tables created in the schema but I don't know how to get the detailed information of how it was created. Like the configuration used, the orientation, etc.
How do I get this ...
2
votes
1answer
136 views
Bitmask Flags with Lookup Tables Clarification
I've received a dataset from an outside source which contains several bitmask fields as varchars. They come in length as low as 3 and as long as 21 values long. I need to be able to run SELECT queries ...
1
vote
2answers
63 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
14 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
...
2
votes
1answer
49 views
What are the risks for logging across databases via a trigger?
I've searched for this online and had mixed or unclear responses, and after posting on superuser, was directed over here.
On SQL Server 2005, we currently log certain table changes via triggers using ...
1
vote
4answers
6k 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 ...
1
vote
1answer
62 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
87 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 ...
2
votes
1answer
600 views
How to Convert Horizontal to Vertical Array?
I need to create a query (suitable for Standard Edition) that has data from multiple columns (Columns 1-6 with corresponding Date Started and Date Completed data) displayed vertically, but also has ...
0
votes
0answers
22 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 ...
0
votes
2answers
58 views
Database search with multi joins
I have a MySQL database and I want to perform a little bigger search.
I have about 10k records in one of the tables and It's expected to grow, but slowly.
The biggest problem is that to perform the ...
2
votes
1answer
43 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 ...
0
votes
3answers
18 views
Mysql - How to optimize retrival time in a table
I have query like this! which has 200 million Records in a single table.. I am using BTree Indexes in my table...
mysql> select COUNT(DISTINCT id) from [tablename] where [columname] >=3;
...
1
vote
1answer
81 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,
...






