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
0answers
31 views

Moving Large Tables and All Indexes to a new File Group

I'm looking at implementing File Groups on an existing database that's roughly 600GB. The largest hurdle I have is actually setting this up in production. I need the database to still be available but ...
0
votes
1answer
37 views

How can I choose the best autogrowth option for my new database? [duplicate]

I want to create a new database that I can use for testing, restoring it from a full backup from a production database. These backup file sizes are around 45,486KB, and the production database size is ...
0
votes
1answer
14 views

MySQL table doesn't exist

What I did before the disaster was: vi /etc/my.cfg I added innodb_buffer_pool_size=4G innodb_buffer_pool_instance=2 innodb_read_io_threads=12 innodb_write_io_threads=12 innodb_io_capacity=300 ...
-1
votes
1answer
70 views

Is SQL injection a neccesary feature? [closed]

[EDIT] Is there a technical case for a protocol which supports SQL commands that can be hijacked by their own arguments?[/EDIT] From my understanding SQL injection exists because it is possible to ...
5
votes
1answer
220 views

Get specific result without using loop

I've a table in which data is like this for single user ID - Number - SubNumber - Name 1 101 201101 Jack 2 101 201102 Jack 3 101 201103 Jack 4 101 ...
0
votes
1answer
24 views

Setting a default principal server in SQL Server 2008

This should be a pretty simple answer but I can't find anything on it searching the web. SQL Server 2008 R2, mirrored with a witness: Node1 (Principal) Node2 (Mirror) Node3 (Witness) If Node 1 ...
0
votes
1answer
23 views

Add '%' sign to MySQL results

I am using a query to calculate total percentage but I want a '%' symbol to appear next to it. Any ideas that could help me My query so far is SELECT student.StudentID, student.Name, ROUND ...
0
votes
1answer
36 views

SQL update next row in select

I have ran into a problem with SQL. I have a list with car and mileage data. What I need to do is for the empty fields to calculate data. Each row has a field for KM (mileage in KM metric unit), ...
0
votes
0answers
34 views

Table per user and MERGE for analytics aggregation [closed]

We have a very large amount of data in a single table and for various reasons we are doing a DB re-achitecture and decided to break this into multiple tables - one per user (e.g. moving from ...
0
votes
1answer
24 views

Query MongoDB collection and find rows from 7 days ago

I have a MongoDB collection called messages and this is an example document for that collection: { "_id": { "$oid": "551943eee4c6acf40fe5a0f2" }, "sender_id": { "$oid": ...
0
votes
2answers
43 views

Duplicate sequence of rows

I have a history table (EnrollmentHistory) used to track changes to another table (Enrollment) in my database. The EnrollmentHistory table is populated by a trigger that fires whenever a change is ...
0
votes
0answers
19 views

How do I modify an access query to select a row based on one column when other column information is not distinct?

I have three main tables in Access 2007 that I query to get the Class, Skills, and Students. Mutliple other tables are included in the query to pull other information. If a person learned the same ...
0
votes
2answers
28 views

Get rows where lastLoginTimestamp is in last 7 days

I'm trying to get the rows from a table where lastLoginTimestamp is in last 7 days and I'm doing as follow: SELECT * FROM representative WHERE DATE_SUB(lastLoginTimestamp, INTERVAL 7 DAY) ...
0
votes
0answers
25 views

SQL HELP - Latest date and unique by user

NAME + LAST_LOGIN_DATE_TIME ============================= Anna 12-DEC-14 Micky 24-JAN-15 Anna 31-JAN-15 Micky 09-FEB-15 Micky 02-MAR-15 I am looking to pull up unique name's with ...
-1
votes
0answers
24 views

Connection timeout expired during select query on sql server 2000 8.00.194

I am trying to fetch data from sql server 2000 8.00.194 on Lan using select query and i get error . According @rebarry young Solution it can be memory issue. So tried executing same query using ...
2
votes
1answer
23 views

Select multiple rows based on date interval from two fields

I am still learning SQL and I would like to do something that I dont know if it is possible. I have a table in which each record has a initial date and a final date. I would like to create I query ...
-1
votes
1answer
52 views

Replace SQL Server with another DBMS [closed]

In our current application (C#, ASP.NET) we are using SQL Server database. My superiors are planning to move from SQL Server to another database considering the amount of investment involved with ever ...
0
votes
3answers
37 views

MySQL - How do I Calculate an Average Value Over a Period of Time When Only Value Changes are Recorded

I am tracking the sales price of various items, and I would like to calculate the average price of each item over a period of time. My simplified tables look like this: Items ------------------ |key ...
0
votes
1answer
56 views

Automate SQL Server restore from Prod to Dev

I would like to setup an automated restore job which takes the latest timestamp .bak file and restores it into the DEV instance. I currently have a job on the DEV box that uses the UNC path to the ...
0
votes
1answer
18 views

SQL queries failing, Memory not releasing

I have a SQL Server 2008 R2 with 8GB of ram and SQL Server is limited to 6GB. It seems to not be releasing the memory its used, and at some point future queries begin to fail. This is a mirrored ...
-4
votes
0answers
36 views

Oracle to SQL Server query conversion. Getting “Argument data type int is invalid for argument 1 of substring function.” error

I tried to convert a SQL query from Oracle to SQL Server. Oracle query: SELECT T@o_NUMBER(T@o_CHAR(GETDATE(),'HH24')), T@o_NUMBER(SUBSTR(T@o_NUMBER(T@o_CHAR(sysdate,'MI'))/15+1,0,1)) INTO ...
-4
votes
1answer
22 views

From keyword not found? [closed]

SET ECHO ON SET HEADING OFF SET FEEDBACK OFF SELECT * FROM GLOBAL_NAME; CREATE TABLE CAR(REGO CHAR(8) NOT NULL, MAKE VARCHAR(20) NOT NULL, CONSTRAINT CAR_PKEY PRIMARY KEY("REGO")); INSERT INTO CAR ...
3
votes
1answer
69 views

SQL Server index causing incorrect behavior on cursors

I have a SQL Cursor that's behaving incorrectly as soon as we added an index to a table. Here's a trimmed-down example of the query causing issue: DECLARE @CUR_CRDATE NVARCHAR(8) DECLARE ...
0
votes
0answers
25 views

Query that return comma separated list of tuple

For example I have these two table: Table user_score: user_id/ tag_id / score 1 100 0.5 1 200 0.2 1 300 0.3 Table place_tag_count: place_id / tag_id / ...
0
votes
0answers
10 views

Prompt user for Query Paramater MS Access [migrated]

Is it possible to have a user choose yes/no and add a paramater in a query based upon that answer? I have a table that has a 'status' field. One of the statuses can be complete. There is a report ...
4
votes
3answers
82 views

Scalable query for running counts of events within x previous days

I already posted this question on stackoverflow but I thought that I might get a better answer here. I have a table storing millions of events occurring to users: ...
0
votes
1answer
39 views

GRANT permission to access to respective creator

Does the following command: GRANT SELECT ON EVENT TO STUDENT; grant student access to whole EVENT table? If yes, how to only give STUDENT access to EVENT(s) record created by respective STUDENT?
0
votes
1answer
25 views

IS-A relation when defining tables

I already asked this question on SO, prior to realizing that there may have been a more suitable place. I am trying to implement an IS-A relationship between tables. Say I have a singer and a band ...
0
votes
1answer
12 views

SQL CHANGE DATE FORMAT IN BULK

I have a database with several hundred fields but my data structure is wrong. It is currently in uk format as follows: d/m/y 01/01/85 01/01/96 23/12/87 What would be the most efficient way to change ...
0
votes
4answers
30 views

Aggregate data from two tables with different field names

I have two tables that each have date and amount fields. This is for a donation system so one is pledges and the other is donations. Here are the structure of relevant tables and fields: pledges ...
1
vote
1answer
53 views

SQL query to sum a column prior to date and show all entries after that date

I have a database function that sum a column prior to a date and after that date show all entries one by one. that function return the data ordered by a common field and apply the sum by date every ...
2
votes
2answers
66 views

Check if contiguous date interval exists

I have a table in PostgreSQL which describes some events that have a start date and an end date: CREATE TABLE my_table ( event_id serial NOT NULL, start_date timestamp without time zone NOT ...
0
votes
1answer
17 views

MS Access: adding column if not exist (or try/catch it)

this is an easy question, but I can't find out the solution... I have to check if a column exists and add it if the test is negative. How can I do with only sql code? This is the syntax for SQL ...
0
votes
1answer
14 views

represent multiple entities to one entity relationship

If suppose, I have following tables: Here, person can own either home or car. person can't own both at a time. If person owns home, then owns field will be equal to 1, if it owns car, owns field ...
1
vote
1answer
36 views

How to edit data to 2 tables using MySQL Workbench

How to edit data in 2 tables using MySQL Workbench (or can I)? I use the below query to get the data but unable to edit it from the table (or Form Editor). SELECT * FROM TABLE1 ...
-1
votes
1answer
21 views

How to data transpose in sql view?

Table1 Name CITY RANK Manish New delhi A Akash New delhi A Akash Aligarh B Vinay Barh C I have to transpose like Name New Delhi Aligarh Barh Manish A ...
1
vote
1answer
20 views

Recover deleted data SQL Server

On 03/19 one user had deleted the data from 3 tables from one of the databases that we have. Now we have the full backup of that database each day. What we want to do is to restore the deleted data ...
1
vote
1answer
19 views

Update incoming rows based on % calculation

Below is the business requirement which I have to achieve... As a Sales Data Operations process/product owner, I want to be able to identify share class conversions (aka "wash trades") coded as ...
1
vote
2answers
48 views

Slow Select over View

My simple SELECT statement on a view in Postgres 9.3.1 is pretty slow. The receipts table has 20 million entries and the other one has around 17k. But I still think it should be faster than ~16 ...
1
vote
0answers
73 views

Strange IO stall values in sys.dm_io_virtual_file_stats

Values for io_stall_read_ms seems to be higher than actual run time for query. The setup: create database filestats; use filestats; create table t1_primary( a int identity ,b int ,c ...
0
votes
1answer
30 views

building structure for employee office relation

I have a table defined like this empid fromdate todate office_ID 1 2012-03-01 2014-04-2 1 1 2014-04-03 ---- 2 2 2012-03-01 ...
0
votes
1answer
22 views

Find all tables in a DB with column names that contain that substring?

Say I have these three columns student_id, name, identify in three different tables in the same database. The query should search for column names that contain that substring. i.e. id should return ...
0
votes
1answer
22 views

detect what columns to select depending on a column value of the same table

I am trying to build a query which returns different columns of the table depending on a column of the same table. Say, a column represents a type of item. This is my temporary solution, in which I ...
7
votes
3answers
242 views
+100

Mathematical equality of two SQL statements

Is there a way to get check the mathematical equality of two SQL statements? I have two SQL statements: SQL_STATEMENT_1 SQL_STATEMENT_2 Running both statements on data and comparing the output ...
0
votes
0answers
21 views

Postgres count of delimited items in bytea encoded string

How would you get a count for each of $ delimited Individuals in each of the group_names? (Example: SomeGroup has 1, This Is Another Group has 8) thedb=# select group_name,encode(group_data,'escape') ...
1
vote
1answer
45 views

Rebuild vs Reorganize [duplicate]

I currently have a maintenance plan that is reorganizing indexes everyday and I would like to know if you reorganize an index everyday would you ever need to rebuild the index? If so, why?
0
votes
1answer
133 views

SQL Query - Possibly the most poorly written query in the history of mankind

Having a major headache trying to tune this query and looking for help, a programmer who had no idea what they were doing messed with this query and it is currently being used in production and it ...
0
votes
1answer
36 views

MySQL - How to replace a given value from multiple columns when using SELECT?

I need to SELECT a set of rows of a given table whose structure looks like - 1º line is the name of columns A01 A02 A03 A04 A05 ... A200 99999 99999 10 753 99999 ...
0
votes
0answers
32 views

Cannot insert into table

I have created a table called users in my computer by the following method. <table name="users"> </table> Now I am trying to insert a record in it by the following method. ...
0
votes
0answers
19 views

Procedure or function 'sp_InsertImages' expects parameter '@Img_path', which was not supplied [migrated]

i have passed img_path in my code nd procedure but it show me error please anyone help me. my procedure is : create proc sp_InsertImages ( @Img_path nvarchar(max), @product_id numeric(18,0), ...