Most Popular

1500 questions
50
votes
8 answers

Writing select result to a csv file

We need to write the SELECT query results to a csv file. How can it be done using T-SQL in SQL Server 2008 r2? I know that it can be done in SSIS, but for some reasons, we don't have this option. I tried to use the suggested proc in the article…
Sky
  • 3,684
  • 16
  • 49
  • 68
50
votes
4 answers

How to update one table based on another table's values on the fly?

I have a table in the name of ips as below: CREATE TABLE `ips` ( `id` int(10) unsigned NOT NULL DEFAULT '0', `begin_ip_num` int(11) unsigned DEFAULT NULL, `end_ip_num` int(11) unsigned DEFAULT NULL, `iso` varchar(3) DEFAULT NULL, `country`…
Alireza
  • 3,636
  • 10
  • 37
  • 44
50
votes
5 answers

Aggressive Autovacuum on PostgreSQL

I'm trying to get PostgreSQL to aggressively auto vacuum my database. I've currently configured auto vacuum as follows: autovacuum_vacuum_cost_delay = 0 #Turn off cost based vacuum autovacuum_vacuum_cost_limit = 10000 #Max…
CadentOrange
  • 773
  • 1
  • 8
  • 10
50
votes
4 answers

How can I move a MySQL database to another drive?

I'm using MySQL 5.5 on a local machine to analyze a large amount of government data. I've created a local database that resides on my default drive (Win7 C: drive). I'd like to store the data on my E: drive, a large eSATA external drive. What steps…
user1243473
50
votes
1 answer

Is there a maximum length constraint for a postgres query?

The app we are building might execute quite a big insert queries. Is there limit that my postgres query can have only a certain number of characters?
Kannan Ramamoorthy
  • 647
  • 2
  • 7
  • 8
50
votes
2 answers

SQL Server - granting permissions to an entire schema vs. object?

I'm very green when it comes to the world of database permissions management in SQL Sever. Let's keep an example simple. Say account 'admin' is the owner of schemas A, B, and C. There another account 'minion' that you want to have full rights…
user45867
  • 1,683
  • 5
  • 22
  • 38
50
votes
2 answers

Best way to get last identity inserted in a table

Which one is the best option to get the identity value I just generated via an insert? What is the impact of these statements in terms of performance? SCOPE_IDENTITY() Aggregate function MAX() SELECT TOP 1 IdentityColumn FROM TableName ORDER BY…
AA.SC
  • 4,063
  • 4
  • 25
  • 43
49
votes
9 answers

Is there a tool like Microsoft's "SQL Server Profiler" for MySQL?

While developing on MySQL I really miss being able to fire up a profiler. I find SQLyog is a good enough replacement for Query Analyzer but have not found a tool that works like SQL profiler. For the MySQL folk who have not seen Microsoft's SQL…
Sam Saffron
  • 1,104
  • 1
  • 10
  • 12
49
votes
2 answers

Replace multiple columns with single JSON column

I am running PostgreSQL 9.3.4. I have a table with 3 columns: id name addr 1 n1 ad1 2 n2 ad2 I need to move the data to a new table with a JSON column like: id data 1 {"name": "n1", "addr": "ad1"} 2 {"name": "n2", "addr":…
AliBZ
  • 1,789
  • 5
  • 16
  • 27
49
votes
2 answers

Is there any difference at all between NUMERIC and DECIMAL?

I know that the NUMERIC and DECIMAL data types in SQL Server work the same: the syntax for creating them is the same, the ranges of values you can store in them is the same, etc. However, the MSDN documentation describes the relationship between the…
KutuluMike
  • 1,589
  • 2
  • 14
  • 13
49
votes
15 answers

Eliminate duplicates in ListAgg (Oracle)

Prior to Oracle 11.2 I was using a custom aggregate function to concatenate a column into a row. 11.2 Added the LISTAGG function, so I am trying to use that instead. My problem is that I need to eliminate duplicates in the results and don't seem…
Leigh Riffel
  • 23,854
  • 16
  • 78
  • 152
49
votes
6 answers

SSD vs HDD for databases

I am trying to purchase a new Server to run MySQL Server on. This new server will be a slave of my main machine. However, this server will be dedicated for reporting only "Lots of reads and complex queries." Now I am looking into investing into…
Mike
  • 609
  • 2
  • 6
  • 6
49
votes
6 answers

How to get all roles that a user is a member of (including inherited roles)?

Let's say I have two Postgresql database groups, "authors" and "editors", and two users, "maxwell" and "ernest". create role authors; create role editors; create user maxwell; create user ernest; grant authors to editors; --editors can do what…
Neil McGuigan
  • 8,423
  • 4
  • 39
  • 56
49
votes
4 answers

Clustering vs. transactional replication vs. availability groups

Assuming you need to make sure your application that relies on SQL Server 2012 as its database backend is available around the clock, even if one server machine fails. As a developer and not a DBA, I am struggling to understand when to use which…
marc_s
  • 8,932
  • 6
  • 45
  • 51
49
votes
8 answers

Is it possible to mysqldump a subset of a database required to reproduce a query?

Background I would like to provide the subset of my database required to reproduce a select query. My goal is to make my computational workflow reproducible (as in reproducible research). Question Is there a way that I can incorporate this select…
David LeBauer
  • 3,142
  • 8
  • 30
  • 34