An acronym for "Structured Query Language" (it's not the name of a specific DBMS product), 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 ...

learn more… | top users | synonyms (1)

0
votes
0answers
17 views

Turning multiple fields in column to row

I have an issue that has really stumped me in MSSQL I have recently had the need to insert a row in to a table, made up from a number of fields. I want to make the one row up from something like the ...
-1
votes
0answers
15 views

Can I add dummy rows to a crosstab query in Access? [on hold]

Is it possible to add dummy row headings to a crosstab query in MS Access when the data doesn't exist in the source table/query? I'd like to indicate that I'm aware that a category exists, even though ...
1
vote
2answers
32 views

New to databases - does my ERD reflect good database design?

I'm making a database to hold data for a media player that I'm working on. Originally, I thought to use one table with the fields: {filePath,artist,title,album,track_number,length,date,artworkUrl} ...
0
votes
0answers
32 views

Oracle - Slow queries without prepending schema name or providing hint

I am logged in as the schema owner in Oracle 11gR2 on Linux. I have 55 million rows in table. select max(col) from table; - takes 300 seconds (index full scan) select max(col) from schema.table; - ...
-2
votes
1answer
14 views

Query required to get data from same column

I trying get data from table having customer colums and details column details columns having several values like, Pen,Pencil, notepad,Pins etc. I want to query customer having pen and pencil. Pls ...
0
votes
0answers
8 views

PostgreSQL query slow when using tsvector and ORDER BY despite having index

Running on a large database (around 1.5G) The following query takes about 70 seconds to run, SELECT x FROM DBText x WHERE x.status = 2 AND x.publishedTime < 4574590406397 AND x.service = ...
0
votes
0answers
18 views

Oracle SQL Statement alter index and add partition

I have an index in which I have to remove one column and reindex back for rebuild: ALTER INDEX <index_name> REBUILD; Is it possible to add partition when I rebuild an index. Partition will ...
0
votes
0answers
15 views

Advice on MYSQL DELETE on CASCADE, UPDATE on CASCADE features

I have 2 tables called copyrigihtinfo and sourceinfo and many to many to relationship table cp_src_junction with following data. copyrightinfo table cp_pk cp_info 1 copyright (c) 1991-2000, ...
0
votes
0answers
18 views

Stored Procedure Issue in Simple Select Statement

Here is my Fiddle Here is My Table : CREATE TABLE IF NOT EXISTS `vehicle` ( `AutoID` int(11) NOT NULL AUTO_INCREMENT, `VehicleCode` varchar(20) NOT NULL, `NumberSeats` int(3) NOT NULL, ...
-3
votes
0answers
36 views

sql query self outer join [on hold]

I have one table name lease there is field lsid,month,amount the lsid is every month same suppose like this lsid lsmonth amount 1 30-nov-2014 50 1 31-oct-2014 100 2 ...
0
votes
1answer
26 views

How to delete row from table later than date?

I have a simple table: MyTable: -Id int primary key -Name varchar(MAX) -Deleted bit Now i want delete rows created later that 15.12.2014. But how can you see i don't have a any date columns in my ...
0
votes
0answers
9 views

In Forward Engineering I have an error called 'table does not exist'

This is my forward engineering code. -- MySQL Workbench Forward Engineering SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, ...
0
votes
0answers
17 views

My database engine cannot see one of the drives

I installed SQL Server 2012 on a VM that has two harddrives, C and E. I can log into the Database Engine, but when I attempt to attach a database that is on E, Drive E is not available. Only Drive C ...
0
votes
0answers
22 views

Query plan reads vs statistics io reads

I have a very strange problem. When I run a query with SET STATISTICS IO ON, it shows that I had a total of 183 reads. But when I look at the query plan dmv it shows I did 555,132 reads. I cleared the ...
0
votes
1answer
11 views

storing query results in a variable in mysql and using it in another query

I have a following query which runs perfectly fine: SELECT count(*) as total,l.state as state FROM db1.table1 cd inner join db2.table2 l ON ...
0
votes
1answer
20 views

How can I create a bool column for a view based on the result of a statement?

I'm using PostgreSQL as my database. CREATE TABLE groups ( id SERIAL NOT NULL, name TEXT NOT NULL, PRIMARY KEY (id), UNIQUE (name) ); CREATE TABLE users ( id ...
0
votes
0answers
5 views

Can MySQL Index Merge an Composite index with a single column index?

I am tuning a query and currently have an index as following : Index 1 : (col1, col2) An example query would be : SELECT * FROM t1 WHERE col1 = '1' AND col3 = '2'; I have created an index on ...
2
votes
1answer
29 views

Get products of category plus all child categories till leaf nodes

We have a hierarchy which looks this: Now the problem is that most products are only connected with 1 category, which is most of the time the lowest level. I am trying to get ALL products below a ...
2
votes
0answers
26 views

Can I convert SQL Server 2008 full db to SQL Server 2005?

Recently I converted my SQL Server 2005 database to SQL Server 2008. Now I can't attach that db to SQL Server 2005. I do not have any backup of that db file as well. I have tried to generate scripts ...
0
votes
1answer
16 views

Need help in putting the single quote and constant timestamp in plsql

Please help me in appending the Single quotes and constant timestamp to my query output. Given below is the expected output from my param file. Note: Query is executed through sqlplus Expected ...
2
votes
0answers
24 views

How to store a 64-digit key of alpha numerical values into MySQL Database

I am student studying in Database Administration (first year), one of our task requires a to design a login form for corporate and regular users. Below are the requirements for the username and ...
1
vote
1answer
33 views

How do I get the count for time periods?

I have a table with the following columns. [ComputerGroupid], [Computerid], [Userid], [loginTime], [logoffTime] And my requirement is to get the table with the below information ...
0
votes
1answer
21 views

join on just the next closest date?

I want to get a table of [file], [folder], [DateAdded], [DateRemoved] I have a log table of changes that has [file], [ChangeDate], [OldFolder], [NewFolder] Files have moved in and out of ...
0
votes
0answers
16 views

Slow Query Performance - Can't Debug

I have a MySQL query that I am trying to debug the performance issue but cannot. I know that the majority of the query is reading/processing rows (Sending Data state). However, in the explain output, ...
2
votes
1answer
50 views

How do I create a partition using a bit field in SQL Server 2014

I have a table where data is archived. I need to keep this data as it is rarely viewed. Instead of moving archived data to a separate table, I wanted to create a partition on the Archived field. When ...
3
votes
3answers
68 views

Help with SQL Query to XML output

I have the following query: SELECT [ID] AS [NewID] , ( CASE WHEN LEN([MiddleName]) > 0 THEN [LastName] + ', ' + [FirstName] + ' ' + LEFT([MiddleName],1) + '.' ...
0
votes
1answer
14 views

DELETE from OPENQUERY alias not working

I'm trying to use the following code to execute a DELETE statement on a linked server. I'm trying to delete all records from the remote server where there is a match on a certain ID field in both the ...
0
votes
1answer
19 views

Merging 2 queries together

I have 2 query results that need merged together where periods are alike, adding a the column 'seats', using a '0' the period doesn't exist. Before: tdate period staff ...
0
votes
2answers
37 views

Suspended query causing high CPU usage

Environment detail: SQL Server 2008 R2. I have applications running on JBoss that access the DB using JDBC driver. Issue: My online DB server was experiencing high CPU usage. Using the ...
1
vote
2answers
32 views

Filling in date holes in grouped-by-date SQL data

The actual problem involves far more data and joins, but I've created a small sample to demonstrate the issue: -- create example table DROP TABLE dbo.EventRecords GO CREATE TABLE dbo.EventRecords ...
0
votes
1answer
23 views

SQL Server Chain Permission

We have the 2 databases. Reporting HR There are some users who want to extract data from HR database. But we don't want to give direct access to that HR database. So, we created the special ...
-1
votes
2answers
23 views

How to Shift a column up in a ring buffer? [on hold]

I am amazed this question doesn't seem to have been asked before, but if so, my pretty exhaustive searches have not discovered it. I have a simple ring buffer of temperatures in a column from which I ...
0
votes
1answer
16 views

can I use many-to-many relation with weak entity

I have an entity, for example employee(key employee ID), and every employee can have multiple responsibilities. Every responsibility can be tasked to multiple employees. I have 3 options: 1) Create ...
0
votes
0answers
9 views

How is it called when a DB supports FOR XML and XQUERY?

I have my SQL Express 2008 R2 database, on which I heavily rely on two features: Generating XML from relational tables (using FOR XML) Generating relational data from XML (using XQuery) I wonder ...
3
votes
1answer
30 views

the <set clause>'s <multiple column assignment>

I just know a little sql basics and need to write a plain sql syntax highlighter/checker So I'm fighting through the standard... I stumbled over somthing I'm not sure I understand it right, as I never ...
0
votes
0answers
20 views

How to compare between two values in one field depending on another field in SQL* / Oracle Reports?

I have three fields in a table named table_family. One is "relation" it has 3 kinds of values 1 for person, 2 for parents, 3 for son. Other field is "age" and it contains the ages of all the ...
0
votes
0answers
14 views

How to copy architecture of an existing database to a new database in SQL Server

I'm using Microsoft SQL Server 2012 (SP1) - 11.0.3153.0 (X64) Express Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor) and I need to copy the database ...
2
votes
1answer
56 views

Recursive CTE to find unique slug

I have an article table where I want the slug to be unique. CREATE TABLE article ( title char(50) NOT NULL, slug char(50) NOT NULL ); When the user enters a title e.g. News on Apple, I want ...
2
votes
1answer
14 views

Suspect (Torn) Pages recorded in TEMPDB? (SQL Server 2005 SP3)

I have a virtualised SQL Server 2005 (SP3) server that reported the following msg: Database_Name, Database_Id, File_Id, Event_Type, Event_Type_Desc, Error_Count, Last_Update_Date tempdb, 2, 1, 3, ...
-1
votes
1answer
19 views

Sorting a table based on nullable Position field that has to match the position on the result set

I'm using SQL Server 2012 I have a simple table that has a Nullable (int) Position and a (datetime) Created field. I would like to do a select * from this table order by created desc but ...if a ...
0
votes
1answer
8 views

Trigger syntax on phpmyadmin

I can't make this work. I want to create a trigger that deletes the child foreign keys before I delete the parent primary key. This is the code that I am using on phpmyadmin: delimiter // CREATE ...
1
vote
1answer
44 views

Delete back ups more than 2 weeks in sql server

I am not a DBA, I need to delete the USER_DATABASE backups older than 2 weeks. Is this below stmt work for this scenario? EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASE', @Directory = ...
1
vote
0answers
40 views

I can't divide 2 count(*) values without returning zero

The statement I'm using is for a KPI in Maximo and I currently have this statement: select (select count(*) from incident where incident.slanum = 'USERADMIN' and incident.actualfinish > ...
1
vote
1answer
17 views

Create a log file for check which time import has been done and to split the import files

How to create a log table for when does the last import has been done and also for Query for split the records in to 1000 while importing. to avoid the bulk insert For example : If the data ...
0
votes
3answers
61 views

I do not understand SQL Server Transaction Logs

I understand that a Microsoft SQL Server Database has two components: A database file A transaction log file Whenever I make a change to a table, does it get written to both the database file AND ...
0
votes
1answer
49 views

SQL command to copy over 8,000 table entries [on hold]

I have an SQL Server 2008 database, I want to copy the items from one table (about 8000 entries) to a new table, an this be done with the parent ID to link it to the correct record. I'm using a ...
2
votes
2answers
27 views

Get all (non repeated) distribuidores with their paises given a producto_solicitud

I have this schema: And as title says I need to get all records from fabricante_distribuidor by given producto_solicitud.id value. I'm doing in this way: SELECT ...
2
votes
1answer
131 views

Alter table and update in sql server transactions

I'm trying to do an alter table to add a new column on a table, then I would like to do some update on the existing rows in the table to add a value to the recently new added column and finally do a ...
-1
votes
1answer
47 views

How to know which columns value is different between two rows

I am trying to compare two addresses from the same ID to see whether they match. For example: Id Adress Code Address 1 1 123 Main 1 2 123 Main 2 1 ...
0
votes
1answer
12 views

Select Count on Big table take 15 minutes

I try to run select Count on table with like 16M rows, with MySql 5.5 and workbench 6.2. The query running almost 1000sec . Is it normal? The query : SELECT COUNT(1) FROM My_Table when I run ...