Most Popular
1500 questions
57
votes
6 answers
How to combine date and time to datetime2 in SQL Server?
Given the following components
DECLARE @D DATE = '2013-10-13'
DECLARE @T TIME(7) = '23:59:59.9999999'
What is the best way of combining them to produce a DATETIME2(7) result with value '2013-10-13 23:59:59.9999999'?
Some things which don't work are…
Martin Smith
- 84,644
- 15
- 245
- 333
57
votes
3 answers
How to get the timestamp column in only milliseconds from PostgreSQL?
I have a column "created" with type timestamp without time zone default now() in a PostgreSQL database.
If I select colums, it has a nice and readable format per default:
SELECT created FROM mytable;
…
Jonas
- 32,975
- 27
- 61
- 64
57
votes
2 answers
What is the purpose of the database 'owner'?
Today while troubleshooting a service broker problem, I discovered that the database owner was the Windows login of an employee who had left the company. His login had been removed and thus the query notifications were failing.
Supposedly the best…
8kb
- 2,629
- 2
- 32
- 35
57
votes
6 answers
How to insert (file) data into a PostgreSQL bytea column?
This question is not about bytea v. oid v. blobs v. large objects, etc.
I have a table containing a primary key integer field and a bytea field. I'd like to enter data into the bytea field. This can, presumably, be done by one of the PL/…
SabreWolfy
- 919
- 1
- 7
- 16
57
votes
7 answers
EXISTS (SELECT 1 ...) vs EXISTS (SELECT * ...) One or the other?
Whenever I need to check for the existence of some row in a table, I tend to write always a condition like:
SELECT a, b, c
FROM a_table
WHERE EXISTS
(SELECT * -- This is what I normally write
FROM another_table
WHERE…
joanolo
- 13,397
- 7
- 36
- 65
57
votes
3 answers
Why is a .bacpac file so small compared to a .bak file of the same database?
I've been doing backups of my SQL Server 2014 Express databases for import to other servers and noticed a difference in file size between .bacpac and .bak.
Why is a .bacpac file so small compared to a .bak file of the same database?
Thanks for any…
Chris
- 673
- 1
- 5
- 5
57
votes
3 answers
What is the optimal data type for an MD5 field?
We are designing a system that is known to be read-heavy (on the order of tens of thousands of reads per minute).
There is a table names that serves as a sort of central registry. Each row has a text field representation and a unique key that is…
bobocopy
- 765
- 1
- 6
- 7
56
votes
7 answers
Why should I create an ID column when I can use others as key fields?
Possible Duplicate:
Why use an int as a lookup table's primary key?
So far, I'm accustomed to creating an ID column for every table and it is practical in a way that it makes me not think about decision making about primary key theories.
The…
Uğur Gümüşhan
- 707
- 2
- 6
- 12
56
votes
3 answers
How can I see the current Database Mail configuration?
Our SQL Server (2008) instance is configured to send mail and everything is working correctly, but I can't figure out how to view the existing configuration, in particular the SMTP server.
From SSMS I can only start the configuration wizard, and I…
Alex
- 663
- 1
- 5
- 6
56
votes
4 answers
Is it possible to store and query JSON in SQLite?
I need to store JSON objects in a SQLite database,
and then do complex queries on it.
I did a table like this:
+--------------------------------------+
|document | property | string | number|
+--------------------------------------+
|foo | …
tuxlu
- 561
- 1
- 4
- 3
56
votes
4 answers
Does updating a row with the same value actually update the row?
I have a performance-related question. Let's say I have a user with first name Michael. Take the following query:
UPDATE users
SET first_name = 'Michael'
WHERE users.id = 123
Will the query actually execute the update, even though it is being…
OneSneakyMofo
- 663
- 1
- 5
- 5
55
votes
5 answers
How can I use a default value in a Select query in PostgreSQL?
I would like to use a default value for a column that should be used if no rows is returned. Is that possible in PostgreSQL? How can I do it? Or is there any other way I can solve this?
E.g. something like this:
SELECT MAX(post_id) AS max_id DEFAULT…
Jonas
- 32,975
- 27
- 61
- 64
55
votes
6 answers
How to import a .sql file in MySQL?
I am trying to import a .sql file using MySQL Workbench and I get this error:
ERROR 1046 (3D000) at line 28: No database selected
I have first created an empty database called with the same name as the .sql file but it doesn't work.
I have also…
Barbara Dreamer
55
votes
4 answers
How to turn off header only in psql (postgresql)
I'm using PostgreSQL 9.1.X
I am trying to build psql script to print results without a header but including a footer.
http://www.postgresql.org/docs/9.1/static/app-psql.html
From the document above
\pset tuples_only
will turn both header and…
skong
- 651
- 1
- 5
- 3
55
votes
7 answers
Why does ORDER BY not belong in a View?
I understand that you cannot have ORDER BY in a view. (At least in SQL Server 2012 I am working with)
I also understand that the "correct" way of sorting a view is by putting an ORDER BY around the SELECT statement querying the view.
But being…
ngmiceli
- 653
- 1
- 5
- 6