Structured Query Language (SQL). For questions about the language, not Microsoft SQL Server (tag sql-server).

learn more… | top users | synonyms (2)

47
votes
3answers
2k views

Huge slowdown to SQL Server query on adding wildcard (or top)

I've got a zoo of 20 million animals which I track on my SQL Server 2005 database. About 1% of them are black and about 1% of them are swans. I wanted to get details of all the black swans and so, not ...
0
votes
1answer
117 views

SQL Server 2000 Replication, Performance, and Query Priorities

I'm a developer and wanting to confirm the following: Does anyone here have experience with SQL Server Replication (transactional) on 2000? We are trying to convince the DBAs to allow this in a ...
0
votes
1answer
238 views

SQL Server Standard High Availability (HA) with two nodes

Is it possible to accomplish High Availability (HA) with two SQL Server Standard nodes ? We can't use SQL Server 2012 AlwaysOn without Groups as it has single point of failure by using the "single" ...
3
votes
2answers
714 views

Can't get this query to work (left outer join) Postgres [closed]

I've got this query I'd like to get working. I'm trying to count all the instances of a foreign key after a certain date that isn't null, and then left join that to the distinct of the original table, ...
1
vote
3answers
78 views

No of rows to be displayed [closed]

I have 100 records. I want to display only 10 rows of that record default or by specifying the number by using procedure
1
vote
2answers
592 views

DB2: Cannot use RUNSTATS/REORG in trigger definitions?

CREATE TRIGGER MY_TRIG AFTER INSERT ON MY_TBL FOR EACH ROW BEGIN IF SOMECONDITION THEN DELETE FROM MY_TBL WHERE PK IN (SELECT PK FROM MY_TBL WHERE SOMEOTHERCONDITION FETCH ...
0
votes
0answers
35 views

How to install SQL Server 2008 R2 [closed]

My installation is completed, but no instance in not loading (I am on my service account). Show only .in for more browser. Not loading my instance in the database engine. Everything is completely ...
2
votes
1answer
158 views

DATETIME2FROMPARTS alternatives for SQL Server 2008

I am trying to part a datetime value and build it together removing minutes, seconds and so on. I want the values to be hourly. Usually this works on a SQL Server 2012 machine: DATETIME2FROMPARTS( ...
0
votes
1answer
72 views

Query Result Not Perfect on Mysql?

I have table Like This ID | City | Prize _______________________ 1 | Surabaya | Notebook 2 | Surabaya | Notebook 3 | Surabaya | 4 | Bandung | NoteBook 5 | Bandung | PC 6 | Bandung ...
0
votes
1answer
527 views

Need C# Sql Server Project Set Up Guide [closed]

I am creating a window application on c# .net and Sql Server 2008 R2. I will give the setup of this application to my client but I am little bit confuse about SQL Server Database. How the database is ...
1
vote
1answer
3k views

Calling another function inside a postgres function

I have a function A and function B. Function A Name is f_a() and the code is: Select id,address from A; Function B Name is f_b() code is: Select C.address,B.name From (Select id,name from B, (...
0
votes
1answer
12k views

Create database link on Oracle Database with 2 Databases on different machines.

I have 2 oracle databases (db1 and db2) on different machines, lets suppose: db1 on 192.168.1.1 and db2 on 192.168.1.2 What I want to achieve is to create a link on db1 that will allow me to perform ...
3
votes
0answers
90 views

Splitting SQL Server 2008 database [closed]

I manage a 280gb SQL Server database. The structure contains a single database file and many schemas. Each customer has a schema and an associated set of tables. so : MainDatabase : Schema1: ...
0
votes
0answers
323 views

How does tablespace sizing works in Oracle

Let's say I have an input of 20 gigabytes of raw data (text file) which in turn I would into an external table and would then swap partition in order to place them on my database. The question now is ...
2
votes
2answers
25k views

How to empty a column in mysql [closed]

I have table Like This ID | name | prize | ____________________ 1 | Mike |Handphone 2 | Josh | 3 | Sony | PC 4 | Jack | let's say my table have 1000 rows. If I want To Empty only the Prize ...
3
votes
1answer
148 views

selective undoing of commited transactions in PostgreSQL

I have inherited a small (<1M rows) PostgreSQL DB which contains complex business rules split across several tables. Updates are very light, reads not so heavy, but the data is extremely valuable. ...
0
votes
0answers
180 views

Recommended plan for 0min RTO and RPO

I have a Windows Server 2008R2 Server, running SQL Server 2008R2 SP2. The server currently only does a full backup once daily. The server's operational hours are between 8am and 5pm. The server's new ...
2
votes
1answer
128 views

To normalize or not to normalizde? (10 fields)

I'm helping someone to design a database and for a specific case I'm not sure. I have 10 fields - this will never change - that will always be filled and used in every query that could be coming up. ...
1
vote
1answer
1k views

Error deleting SQL Server local database

I'm doing a project in Visual Studio 2012 and it involves working with the given database. As I add the database.mdf to the project (asp.data folder) I got a connection error, but nothing out of the ...
2
votes
1answer
278 views

Getting Information on active Restore in TSQL / SQL Server Management Studio

On my server a database is currently restoring according to the SQL Server Management Studio In the history SELECT * FROM MSDB..RestoreHistory WITH (nolock) WHERE destination_database_name = 'myDB' ...
1
vote
1answer
87 views

Display a List of used Table and Column

Goal: Display detailed information if database A use database B:s table and its column. if yes, the list will display what is the name of the database B:s table and column that is being used in ...
0
votes
1answer
339 views

Does size of one particular column in a database affect query performance?

I have a table user_list CREATE TABLE IF NOT EXISTS `user_list` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `username` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `email` varchar(...
0
votes
1answer
1k views

Consecutive Rows to fetch from SQL server table

We have following table structure +---------+------------+-------+---------+------------+---------+-----------+----------+--------+ | EmpCode | InDate | Shift | ArrTime | OutDate | DepTime | ...
2
votes
4answers
4k views

How To Update Random ID to a table in mysql?

I have table like this: ID | City | Prize | ---------------------------- 1 |Surabaya | HP 2 |Surabaya | Watch 3 |Surabaya | Bag 4 |Semarang | 5 |Semarang |Watch 6 |Semarang | 7 |...
0
votes
1answer
3k views

Insert blank row in the postgres query result

I have below table after run a postgres query select * from tbl 1 type_1 name-1 2 type_1 name_2 3 type_2 name_3 4 type_2 name_4 5 type_3 name_5 how can I add a blank line in between each type so I ...
0
votes
1answer
782 views

Unique key in SQL Power Architect? Forward Engineering

I want to know if there is a way to create unique keys (not PKs) in SQL Power Architect using forward engineering. I've searched google, saw the tutorials by the software vendor, and checked out in ...
0
votes
0answers
47 views

Have a lot of customers -> which design in SQL Server 2008R2 should be chosen [closed]

I have a task and I don't know how solve it :) So, we have a lot of customers who should use SQL Server for their applications. Design is standard and simply: Customer -> Remote Desktop -> ...
0
votes
1answer
878 views

Select values from 2 tables with same properties

I am using SQL server 2012, running on windows data-center 2012, under windows azure cloud platform virtual machine. I have the following situation : I have a base settings table lets say as ...
1
vote
1answer
2k views

Store equations/formula in mysql db table

I want to know what is there a way for storing equations or formula in a DB column. Below is the table where I am storing the machines details(master table). But the last column is what I am worrying. ...
1
vote
4answers
251 views

mysql need help optimizing query

I have a table containing servers logs, and another table containing rules to match certain and drop them. The logs tables contains around 1 million rows, and there are about 20-30 rules. The ...
3
votes
3answers
429 views

Joining and filtering two sets of the same table

I guess this is an easy and stupid question. Consider this MySQL purchase table (where p_id is autoincremented): +---------+-------------+---------------+---------+ | p_id | item_id | user_id ...
4
votes
1answer
219 views

SQL Server's BACKUP DATABASE - how to access the original exception?

DECLARE @DbName SYSNAME; SET @DbName = 'MyDatabase'; BACKUP DATABASE @DbName TO DISK = 'C:\MyDatabase.bak' WITH INIT, NAME = 'MyDatabase-FullBackup', STATS = 5; This, sure enough, ...
0
votes
1answer
303 views

Complex Oracle SQL to sum data

I am building a SQL query in Oracle 10g that needs to sum overtime hours for the base table, but needs fields from the parent tables as well. I am looking for the fastest way to build the query. The ...
0
votes
2answers
99 views

Amount of memory used by postgres

I am curious as to whether the performance of postgres depends on the amount of RAM available. i.e. will postgres performance(during reads) on several runs get affected by the amount of RAM that is ...
0
votes
2answers
2k views

Join in same table

I have a table employee +--------+----------+------------+ | emp_id | emp_name | manager_id | +--------+----------+------------+ | 1 | abc | 2 | | 2 | pqr | 3 ...
4
votes
1answer
6k views

Select next and previous rows

I have the following table: CREATE TABLE post ( id bigint primary key, thread_id bigint, is_notice boolean, title text, content text ) I display the list ...
0
votes
0answers
55 views

Should triggers be used as an extra precaution to enforce business rules? [closed]

I'm new to SQL Server, and I was wondering: how often do DBA's use triggers to enforce business logic? As long as your security is tight and no user has db_datawriter (or some other all-writing ...
1
vote
4answers
14k views

how to write conditional where clause query

Hi I want write the mysql query conditionally. I am basically using the Wordpress, please have a look at my same tables. tbl1 id name 1 A 2 B 3 C 4 D 5 E tbl2 id post_id key ...
0
votes
1answer
2k views

Why are timestamps not always increasing with concurrent inserts?

I'm seeing some unexpected behavior with timestamp (rowversion) columns . I created a test table: create table Test ( Test_Key int identity(1,1) primary key clustered, Test_Value int, ...
0
votes
1answer
337 views

Data Analysis with MongoDB or MySQL

I have a need for processing some data in order to come up with some statistic. This is the scenario: Each user can answer several questions from the question list. They pick their answers from a ...
0
votes
1answer
4k views

SQL Query with multiple conditions on date

I want to write a query with condition on dates for below table and sometimes it requires great thinking. StartDtm StopDtm 2013-11-03 00:00:00.000 NULL 2013-...
0
votes
1answer
76 views

SSMS gives error if column name is “MERGE” where as other keywords works

IN SSMS create table if we include sql keywords in column name then it will be wrapped around square brackets "[]" automatically and the table gets created without any error generally. But if we ...
-1
votes
0answers
13k views

Errors trying to install SQL Server 2012 on Windows 7 [closed]

I am getting the above error message when i try to run the setup file. Microsoft SQL Server 2012 Service Pack 1 Setup The operating system on this computer does not meet the minimum ...
0
votes
1answer
1k views

What is blocking 'SELECT… WITH(NOLOCK)'?

While following BrentOzar's "How Much is Offline During an Index Rebuild?" I was curious to run: SELECT Quantity FROM [Production].[TransactionHistory] WITH(NOLOCK) while executing a rebuild ...
0
votes
1answer
36 views

Conditional when creating a domain

How can I define or change a domain based on another attribute value? F.e. domain for salary is a numeric value > 500. But if a date the person was hired > January 1st, 2013, then the salary must be >...
1
vote
3answers
877 views

Proper use of database functions for business logic

I have a database in postgres with 147 tables; these tables contain data generated by functions that have most of the logic of the system, for example how to build an accounting entry. These ...
0
votes
1answer
42 views

Oracle sql plan for a select with procedure in terms section

Is there any difference in optimizing a plan to execute any sql request in case of using a procedure from a package which checks to display row or not and in case of constructing a plain sql query ...
4
votes
1answer
225 views

SQL query filled Temdb complete Harddisk [closed]

I have a query which was earlier fine but now it is running me out of hard disk space with message that tempdb is full. My Harddisk has 90 gb of space as soon as i run query temdb runs out of space in ...
2
votes
1answer
85 views

What is the appropriate SQL method for “Safe to SUM”?

In SQL Server 2008 R2+ we, unfortunately, have some nvarchar columns storing numeric data. In some cases we want to SUM the data when it can be summed. The problem is that ISNUMERIC() returns 1 for a ...
2
votes
1answer
511 views

SQL Server Replication - setting up scheduler issue

We have tasked to set up a scheduler to synchronize data between a publisher and subscriber on daily basis. The subscription was set using windows sync manager and it runs just fine when run manually. ...