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
55 views

Join conditions and Where conditions in Left Join

STUDENT table contains a list of students in my school Database LIBRARY_BOOK table contains the information of each Book that is with currently with any student. each student is allowed only 1 book ...
0
votes
0answers
31 views

Designing a correct table structure

We are trying to save the Family History of a particular foreign job applicant. Below are the details we have to save. Familiy Member: Father|Mother|1st Brother| 2nd Brother| 1st Sister| etc etc ...
1
vote
2answers
174 views

SQL ssis delete imported rows from source table

I have setup a simple SSIS package that copies data from a source table to a destination table which works. I would like to get the package to also delete the data in the source table that has been ...
1
vote
1answer
40 views

Monitoring the rows in a table

I'm trying to achieve the following tasks in SQL Server. I have a table that I need to monitor its growth. The table shouldn't be containing more than X amount of rows, if there are that many amount ...
2
votes
1answer
53 views

Retrieving latest record using DISTINCT ON is slow [duplicate]

Using Postgres 9.4. I have a table cartests with 5.5M rows. Each row is a car test: \d log.cartests; Table "log.cartests" Column | Type | Modifiers ...
1
vote
1answer
225 views

Designing a High Score/Leaderboard table

I'm looking for input on how to design a highscore table for a game I'm creating. The database I'm using is postgres. That's not really something I can or want to change (unless there's very good ...
1
vote
1answer
92 views

Partial unique constraint spanning multiple tables in postgres

To enforce partial uniqueness in postgres, it is a well known workaround to create a partial unique index instead of an explicit constraint, like so: CREATE TABLE possession ( possession_id serial ...
0
votes
1answer
44 views

What's wrong with my SQL query?

The query I currently am using is this: SELECT locations.id AS locations_id, locations.community AS locations_community, locations.lat AS locations_lat, locations.`long` AS ...
1
vote
1answer
74 views

Find clients who bought more than 1 million units in 3 consecutive months

I want to find the client's code (cCode), who bought more than 1 million units, in three consecutive months. Here is my data: gDate cCode buy 2014-10-22 15108164 1653410 2014-12-22 ...
1
vote
2answers
154 views

OLAP or OLATP - How to determine

I have SQL express server with database that is used by one application. I am trying to optimize the DB but am not sure if the DB is OLTP or OLAP. There is no analysis server installed, the DB is ...
0
votes
0answers
20 views

How to query entire database?

I have an Access database with several tables. All tables have, among other things, a column called Tag and a column called Action. For most records, the Action value is blank, but sometimes it is not ...
0
votes
1answer
79 views

DELETE from Linked Server table using OPENQUERY and dynamic criteria

I'm attempting to run a DELETE statement from my local MSSQL Server to delete appropriate records from a table in my remote linked server using OPENQUERY(). I'm using the following code, but it seems ...
2
votes
3answers
160 views

find all numbers that appear at least three times consecutively

This is a question from leetcode online judge I tried this SELECT Num FROM Logs GROUP BY Num HAVING COUNT (Num) >1 but got runtime error!! Anyhelp would be appreciated
1
vote
1answer
241 views

Remove string after second specific character occures from left

I have this type of values in table column 154646@8@486 45465@6464@654 etc. How can i remove everything after second @ character ? I need to display 154646@8 45465@6464 I can do it only for all ...
0
votes
0answers
58 views

Export a varbinary column to file system using existing authentication

I want to export a varbinary column to a file system. I can use BCP command to export data from a varbinary column, which requires username and password being sent along with BCP command. I can use ...
10
votes
2answers
130 views

Find total duration of each consecutive series of rows

MySQL Version The code will run in MySQL 5.5 Background I have a table like the following one CREATE TABLE t ( id INT NOT NULL AUTO_INCREMENT , patient_id INT NOT NULL , bed_id INT NOT NULL , ...
1
vote
1answer
48 views

Inserting into related tables

I have a database setup with the following schema: CREATE TABLE siteInfo ( siteID SERIAL NOT NULL, siteName TEXT NOT NULL, siteHost TEXT ...
-1
votes
1answer
48 views

delete record if table exists sql

I want to delete record from a table if that table exists Below is the delete statement DELETE FROM UM_CLAIM_BEHAVIOR WHERE UM_TENANT_ID = ? Can I extend this query to check the existence of the ...
2
votes
1answer
124 views

How to update a table with a stored procedure with XML parameter in SQL 2008?

I have the following Stored Procedure query. This query is incomplete. I need help completing this query. Problem: In this SP, I am receiving a well-formed XML string into the SP. My goal is to ...
0
votes
0answers
24 views

Using Code to Access Database Dump via pgAdmin

I looked over this question on how to import a data dump using pgadmin and found the following code: CREATE OR REPLACE FUNCTION db_to_csv(path TEXT) RETURNS void AS $$ tables RECORD; gmdeclare ...
1
vote
1answer
36 views

Will SQL charset wildcard query work on Oracle database? [closed]

I am trying to run the following query SELECT * FROM GEEKYBRAINS.admin_emp where ename like '[sm]%'; It results in an empty set. The admin_emp table has the following data though. I am running ...
0
votes
0answers
22 views

I want to uninstall every program that says “Microsoft SQL” in front of it [duplicate]

I just uninstalled SQL Server 2012 but there is a registryload of Microsoft SQL... entries in the Programs and Features. I want them all gone. I've had issues previously uninstalling them in the ...
0
votes
1answer
33 views

What does normalization say about storing data from objects that use a decorator pattern?

I am just curious as to what the best practices are for storing the data from objects built using decorator design. I have a base class and can decorate it with A, B, and/or C, with A B and C having ...
1
vote
1answer
25 views

Verify failed SQL Server connections to instances on a given server and email them

I am trying to monitor the SQL Server instances on standalone server / cluster server. I would like to setup something from commandline to check for connectivity to each SQL Server instance on the ...
0
votes
0answers
16 views

Modeling attributes relations in RDBMS/NOSQL?

I have a table to hold the relationship between attributes and documents: I need to support the following queries : give all documents where attrib X='value' give me all documents where attib ...
1
vote
1answer
40 views

How do you drop an unnamed check constraint in a PostgresQL table?

I created a PostgresQL table but I added an unnamed check constraint on one of the columns: CREATE TABLE FOO ( id serial primary key, price_range smallint CHECK (price_range > 0), url varchar(255) ...
-1
votes
1answer
81 views

SQL Server CE tools to modify database in network share

I am using SQL Server CE 4.0 SP1. I am using Web Developer 2010 Express to connect to database and perform operations like creating table, modifying column etc. But we cannot connect a database in a ...
0
votes
2answers
52 views

joining same table without a common field

Oracle 11g/SQLPLUS Given single table TABLE with three fields ID, PARM, VALUE, I want to select and group by based on different values of VALUE E.g. ID PARM VALUE id1 accnt France-1 id2 ...
1
vote
0answers
53 views

Defragmentation of SQL Server 2008 indexes

I hate asking this question, but I am having issues defragmenting indexes. I keep using the various defragmentation methods for defragmenting a SQL Server index such as DBCC INDEXDEFRAG and DBCC ...
2
votes
1answer
51 views

Auditing/Logging Help

I'm working on a request to start logging some additional data for PCI compliance. I need to log who, when, and what changed on a set of tables. I set up SQL auditing which would work fine except ...
6
votes
1answer
101 views

Looking for a set-based solution for a rolling 30-day period

I have a stored procedure (MS SQL Server 2008 R2) that needs to see if 10 points/sales fall within a 30-day rolling window. So far, I have a solution that works, but it's not a "proper" solution as ...
2
votes
3answers
94 views

Get last full backup and transaction log backup for each database

How to write script or a query that will display the last full backup and the last log backup for each database on each of the production servers using the system table "backupset" and related backup ...
0
votes
1answer
40 views

same table on different commands (inner join)

Testing some commands of MySQL, I've come across these two comands resulting on the same table. Command 1: select sales.relatory_code, sales.date, destiny.exportation_name from sales, destiny where ...
2
votes
1answer
107 views

Alter table Statement Failed -Msg 207, Level 16, State 1

I wrote a script to add a column in a table and on successful execution update its values. I know it’s just a simple script but what is wrong with the ‘IF NOT EXISTS’ statement why script between ...
2
votes
1answer
81 views

I can't create relationship in my database sql server

I have designed a database for my website. It has 3 tables: user, topic and comment. A user has many topics (or articles) A topic (or article) has many comments A user has many comments I ...
1
vote
0answers
87 views

Backup and FTP SQL Server databases

We plan to backup our SQL Server 2012 databases every night, FTP the backup files to our test servers and restore them. Then deploy the latest schemas to those databases. The reason for this is so we ...
1
vote
4answers
61 views

PostgreSQL execute a default query when no row are returned

I need to calculate the average score of a list of userId. I have a table user_place_score: (user_id, place_id, score) Sometimes I do not have the score (no row for (user_id,place_id) in the ...
0
votes
1answer
37 views

Aggregating two queries and returning a COUNT of some permutations

Hopefully the title can make sense to somebody, so I can get somebody working with a database (BigQuery in my case) to look into into. Given two quarters, I need to find out the # of orders placed by ...
1
vote
0answers
53 views

Does partitioning help if you don't query on the partition value?

Say I have an orders.Order table that is partitioned on CreatedWhen (a datetime column set to GetDate() when the row is created). The table has over 10 million rows and the partition is quarterly ...
0
votes
3answers
78 views

Remove duplicates from different columns

I'm trying to remove duplicates from a set, but the duplicates are in different columns, so for example with this table: ColA, ColB, ColC, ColD ---------- 1, 1, 'ABC', 'DEF' ---------- 1, 1, 'DEF', ...
0
votes
1answer
52 views

SQL access query to count and delete rows > n

Can someone help me with a SQL (Access) query to delete all rows greater than n entries ordered by ID? I.e. say I have 1200 rows of data with ID incremented . I need delete the first amount leaving ...
-4
votes
1answer
53 views

Distinct count of 5 different fields based on multiple values?

I'm not sure how else to explain this so here is an example of what I am trying to accomplish. The problem with this, as you will quickly notice, is that there are repeats in the results. and there ...
0
votes
0answers
27 views

Locally connecting to SQL Server 2012 using Windows Authentication

I have a SQL Server 2012 cluster which I've updated with SP2, and since the update I can't locally connect to the server using Windows Authentication. Yet, I can connect using same credentials from ...
1
vote
1answer
56 views

T-SQL Create Query - Compare and Calculate

I got a mini fantasy league (NBA) and would like some help with a query that turns averages into "ranking points". Basically I got two tables. Source table: This is a table with statistical per ...
6
votes
3answers
362 views

Using DISTINCT in window function with OVER

I'm trying to migrate a query from Oracle to SQL Server 2014. Here is my query which works great in Oracle: select count(distinct A) over (partition by B) / count(*) over() as A_B from MyTable ...
0
votes
1answer
43 views

selecting table1 and table2 with single data row and table 3 with multiple data rows

I want to retrieve data from table1(payments), table2(properties), and table3 (property.assessments). See my visual representation below: tables screenshot Snippets: SELECT a.payment_id, ...
1
vote
0answers
47 views

Is there any way to improve this code?

SELECT tblstud.studid, tblsched.ip FROM tblstud LEFT JOIN tblstudsched ON (tblstud.studid=tblstudsched.studid) LEFT JOIN tblsched ON (tblstudsched.schedid=tblsched.schedid) ...
1
vote
1answer
72 views

Get all the data between Characters [closed]

I am trying to extract all the variable from the following string; string = 'factor1|factor2|factor3' This is just a test string. In real string, I do not know the number of factors. What I want is ...
1
vote
1answer
22 views

Initialize replication from multiple split backup files

We are creating a new Node within our existing P2P replication setup. To be able to create the backup and copy the files I am Backing up to 9 files - each will be about 72Gb: e.g. BACKUP DATABASE ...
0
votes
2answers
69 views

Stored Procedure never completes with Exec, but i can run the Query in SSMS

Im with a problem here. If i run "exec pr_BuscaLog -2', it will run forever ( days, without end )... BUT, If i select the Query and F5, it runs in seconds. I updated STATS but it didn't work. Some ...