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)

1
vote
2answers
2k views

Possibly tempdb out of space or a system table is inconsistent

While running DBCC CHECKDB I got this error Msg 8921, Level 16, State 1, Line 1 Check terminated. A failure was detected while collecting facts. Possibly tempdb out of space or a system ...
3
votes
1answer
85 views

Need help with a Running Total Issue

Using SQL-Server 2008 R2 and Report Builder 3.0 Here is my query without the running total column: SELECT CostManagement_CommitmentDetails.Id ,CostManagement_CommitmentDetails.LineNumber AS ...
0
votes
1answer
90 views

Very slow update with subquery (different tables)

I run this query to update "domains" table based on "log" table: UPDATE domains SET domains.mx_collected = 0 WHERE domains.domain IN (SELECT log.mail as domain_name FROM log WHERE `time` >= ...
2
votes
3answers
3k views

What is the difference between logical schema and physical schema?

While going through Database architecture I came across Schema's . I am very much confused with: Logical schema Physical schema How these two schema exist in the Database? How can these be ...
2
votes
2answers
76 views

Logical problem with a database model

Beforehand the table names and columns are in Spanish, my native language is Spanish. (table names have been now edited to English) I've got a database to manage the tickets sales of a trip that is ...
0
votes
1answer
28 views

Index file - size changed

I realised today that my index file(which is about 250GB) is smaller than yesterday for about 7GB. Everything, I done in the meantime, was index rebuild. Is it possible that index rebuild is the ...
0
votes
1answer
15 views

numbering distinct column values in an ordering but not just displaying the total

I have a column with non-unique entries, we'll call this column "State" (representing the state where an order was shipped to) and a second column called "Times" (representing the times that an order ...
3
votes
1answer
40 views

Unknown _TransactionIndex table in Azure SQL Database

Just noticed today that there is a random table in my Azure SQL Database that is named "_TransactionIndex_{guid}" It has 1 column, Id, that contains 8 GUIDs. Couldn't find any information about this ...
0
votes
1answer
26 views

Query to select distinct name based on several factors

I have a table with the following data (simplified here): ID | PolicyName | Setting | State | Value 1 Default DiskUsage Enabled 1 2 Default Memory Enabled 1 3 Default CPU Enabled 0 4 Personal ...
0
votes
2answers
39 views

Is there anyway to search PL/SQL reserved words with contains function?

Is there anyway to search PL/SQL reserved words with the contains function in the Oracle? We would like to search keywords such as "test for" or "test do" with the contains or catsearch functions ...
0
votes
1answer
16 views

How to get all the months from the last paid date in MySql?

I need to get the all the months from the last_payment_Date for the user from that table for processing purposing. As of now i am using this query.. SELECT `Name`, `Acc_No` FROM `user_table_details` ...
0
votes
0answers
10 views

How to model efficient permission checks for a social network?

The goal is to build a facebook like permission system. So that users can grant other users access on objects based on a direct assignment (allow user X to see posts) or allow users to access them ...
1
vote
1answer
24 views

How to Choose an SQL Database for Simple Data Preparation & Analytics

In the interests of not making this a shopping list: please advise on "how" to choose a the right tool, as opposed to which is the best. E.g: Which questions should I be asking myself / client? What ...
4
votes
1answer
596 views

SQL Server 2008 R2 Restore constantly hanging

I have a SQL Server 2008 R2 SP2 test server that I have to refresh the databases on fairly often, but every time I have to do a restore on, it will hang on me. I use a custom script to check the ...
0
votes
0answers
40 views

Delete and merge duplicate records from joined tables?

I am trying to delete duplicate records from the output of the query below. If they also meet certain conditions i.e., 'different address type', then I would merge the records. From the following ...
1
vote
1answer
35 views

2 Date Ranges - How many days from one range excluding weekends overlap

First - Thanks for your help. I'm looking to create a query in SQL that provides the me the # of days from one date range that overlap another date range and excludes weekends. Example Data: ...
2
votes
2answers
40 views

SQL Insert Statement Persists Two Records When I Need Just One

I have altered it to include hardcoded variables when I pulled this chunk of code from the stored procedure. I ran it independent of the application with the same result. I need one insert statement ...
0
votes
1answer
17 views

SQL Insert Statement Persists Two Records When I Need Just One [duplicate]

I have altered it to include hardcoded variables when I pulled this chunk of code from the stored procedure. I ran it independent of the application with the same result. I need one insert statement ...
0
votes
0answers
10 views

Are there any minimal sqlite extensions for running a server with role based access control?

I need to run an SQL server with role/user based access control in a very resource limited environment. Are there any extensions or open source projects for sqlite to provide this functionality? ...
2
votes
1answer
100 views

Performance impact of Extended Events filter [like_i_sql_unicode_string]

I have created an extended events session in which I wanted to see all queries using nolock hint. I have decided to use it instead of sql trace in order to minimaze possible performance impact. ...
0
votes
3answers
32 views

Converting huge ASCII file to flat and convert

I am not a db administrator but I thought to ask this question here. I have several very large ASCII files (3-5GB each) that I need to extract the data and then sort it. The instructions say to ...
3
votes
2answers
1k views

SQLite writing a query where you select only rows nearest to the hour

I've got a set of data where data has been taken approximately every minute for about three month and the time has been stored as a UNIX timestamp. There is no regularity to the timestamp (i.e. the ...
1
vote
0answers
11 views

Is there a faster way to get UNION ALL behavior in Postgres? [duplicate]

I have a table (t0), in my Postgres DB, with data that looks something like this: t1_id t2_id 1 1 2 1 2 1 4 null 4 null 5 null And I have a query to return my ...
2
votes
2answers
50 views

Oracle: Helping hand writing this query. Do I need a sub query here?

I have the below query that returns the number of orders created on a particular customer number per month for the past 2 years. SQL SELECT TO_CHAR(o.entry_date, 'MM'), SUM(CASE ...
0
votes
1answer
24 views

How do I select all child table records based on condition [on hold]

I have two tables - demographics and PatSubs. Both tables are linked by CaseNumber filed. PatSubs may have one or many substance entry for the CaseNumber. If I do the following: USE [njpies2013] GO ...
1
vote
1answer
149 views

Database Mirroring and Replication in SQL Server 2008 R2

I have configured the mirroring and replication between 4 servers (A,B,C,D).i.e, Mirroring between A to B and C to D, Replication between A and C. The configuration was a success and I am able test ...
0
votes
1answer
34 views

SQL Server database performance is very poor after a month of use

I am quite new to SQL server and have a question regarding database speed. The database (about 50 MB big) was very fast in the beginning. Now, a month later, the speed is a lot worse. I run a script ...
0
votes
5answers
72 views

Database with only text fields

I started working on an existing SQL Server Database System in which most of the fields are stored as text. Except some IDs all fields are varchar (phone numbers, zip codes, Dates, addresses, monetary ...
0
votes
1answer
45 views

Doing a insert across two databases with same collations and getting an error

SQL query : insert DB1.dbo.tbl1 select distinct Number, Name, 'Unknown', 'Unknown', 'Unknown', NULL, 'No', 'GL', 'N/A' from DB2.dbo.tbl1 T2 where T1.Number not in (select distinct AccountNumber ...
8
votes
3answers
9k views

How export a sql server 2008 diagram to PDF filetype?

I want to have a export from my database diagram to PDF or image types.How can I do this? I worked with sql server 2008 R2.
0
votes
1answer
74 views

Stored procedure takes 18 seconds on first load, 0 seconds on subsequent loads, waiting several minutes makes it slow again

I have a stored procedure that returns a lot of data for a business dashboard. On first load it takes 18 seconds, after that it takes 0 seconds, even if I change the input parameters at random it ...
14
votes
2answers
11k views

How to optimize a query that's running slow on Nested Loops (Inner Join)

TL;DR Since this question keeps getting views, I'll summarize it here so newcomers don't have to suffer the history: JOIN table t ON t.member = @value1 OR t.member = @value2 -- this is slow as hell ...
1
vote
2answers
67 views

Fourth inner join to the same table increases query duration significantly

As soon as I add a fourth inner join to a specific table, the query duration increases significantly: sub 1sec to 45sec. The table in question is deployments d4. The SQL Query: select a.id as ...
0
votes
3answers
38 views

how to order a field based on two parts of the row value

I have a field with contents of the form 22/4, 30/8, 30/5, 30/3 I want it ordered in the form 22/4, 30/3, 30/5, 30/8 with the part after / ordered if the part before / is same! Please help!!
2
votes
3answers
312 views

Storing a Shipping Address Best Practice

I'm building a checkout system which needs to store the customer's shipping address in the database and am unsure the best way to go about it. Currently I have an addresses table which stores each ...
5
votes
2answers
187 views

Strange query results for DELETE with ROW_NUMBER

In the following DELETE statement I try to delete all rows except the first one ordered by some criteria. (The actual query makes more sense, this is just a repro. All the sys.objects stuff is just ...
17
votes
6answers
11k views

How do I efficiently get “the most recent corresponding row”?

I have a query pattern that must be very common, but I don't know how to write an efficient query for it. I want to look up the rows of a table that correspond to "the most recent date not after" the ...
0
votes
1answer
69 views

Any way to get database data back?

So I've entered a couple hundred rows of data into a database manually and have begun implementing a Java frontend. However, I got an unexpected result and now when I go back into RazorSQL, the ...
2
votes
1answer
27 views

Best way of finding rows referencing a given id on PostgreSQL

I'm trying to find if there would be anything violating the foreign key constraint when deleting a row, to check if I can delete it or not (can't use ON DELETE CASCADE) For that, I have a piece of ...
0
votes
1answer
115 views

Mysql Select table records which have not been updated since last month

I have a table names 'scoredata' having fields id, lessonid, levelid, studentid, addedate in which score for each day will be entered by the admin. I want to select only those studentid whose score ...
1
vote
1answer
128 views

SQL Server Cross Domain Transcational Replication

Has anyone got any documentation for doing/implementing Cross Domain SQL Server 2012/2008R2/2008 transactional replication document or steps (with screenshot or without screenshot) Thanks for your ...
-2
votes
1answer
36 views

Subqueries in SQL Server 2014 [on hold]

I want to get results that is in more than one row using a subquery. here is what: Note. This is in microsoft SQL Server 2014. Relations: FeeStudent(Feeid, Studentid, MODE,LEVEL, SEM, Paid, Status) ...
1
vote
1answer
84 views

Check entry based on entry in another column

Still fairly new to databases and SQL, so bear with me. I'm trying to check whether or not data can be inserted depending on data in another column, create table Table1 (PaymentType varchar(5) ...
2
votes
1answer
294 views

How to get SQLCMD to output errors and warnings only?

How can you get SQLCMD, when executing a SQL script file, to just output any errors or warnings it encounters? I essentially dont want information based messages to be output.
1
vote
1answer
64 views

Print the execution time on messages Pane?

How I can print the execution time of each query on messages Pane? For example the Select * from tbl1 runs for 10 mins then Select * from tbl2 runs for 15mins and so on.. Select * from tbl1 Go Select ...
-1
votes
2answers
39 views

How is SQL used from an end-user perspective? [on hold]

So I've been learning database manipulation and design and using SQL, but surely a secretary of a company wouldn't be using SQL to directly enter things into the database, so how does that work? For ...
0
votes
1answer
15 views

How to limit results using join in SQL in php [on hold]

I have one table of comments and a second table of students. I want to limit results from these tables using a simple join but I don't know how to. My query is like SELECT com_des,com_doc,usr_name ...
0
votes
1answer
59 views

Is it good practice to keep 2 related tables (using auto_increment PK) to have the same Max of auto_increment ID when table1 got modified?

This question is about good design practice in database. Let see this example, we have 2 interrelated tables: Table1 textID - text 1 - love.. 2 - men... ... Table2 rID - textID 1 - 1 2 ...
0
votes
1answer
169 views

Nested query not recognize external table

i need to a query that show week by week the total amount of imports of any company and in addition add a ranking position depending on that amount. I've made this query but the problem is the inner ...
8
votes
1answer
106 views

Clustered Columnstore indexes in SQL Serer 2014 for data warehousing

I am performance tuning a DWH using indexes. I Am fairly new to SQL Server 2014. MS describes the following: "We view the clustered columnstore index as the standard for storing large data ...