Questions tagged [sql]

Structured Query Language (SQL) is a language for managing data in relational database management systems. This tag is for general SQL programming questions; it is not for Microsoft SQL Server (for this, use the sql-server tag), nor does it refer to specific dialects of SQL on its own.

Structured Query Language (SQL) is a language for managing data in relational database management systems. This tag is for general SQL programming questions; it is not for Microsoft SQL Server (for this, use the sql-server tag), nor does it refer to specific dialects of SQL on its own.

754 questions
241
votes
13 answers

Why use a database instead of just saving your data to disk?

Instead of a database I just serialize my data to JSON, saving and loading it to disk when necessary. All the data management is made on the program itself, which is faster AND easier than using SQL queries. For that reason I have never understood…
MaiaVictor
  • 5,820
  • 7
  • 27
  • 45
235
votes
17 answers

Is it good practice to always have an autoincrement integer primary key?

In my databases, I tend to get into the habit of having an auto-incrementing integer primary key with the name id for every table I make so that I have a unique lookup for any particular row. Is this considered a bad idea? Are there any drawbacks to…
AJJ
  • 2,938
  • 4
  • 14
  • 14
230
votes
19 answers

Why is naming a table's Primary Key column "Id" considered bad practice?

My t-sql teacher told us that naming our PK column "Id" is considered bad practice without any further explanations. Why is naming a table PK column "Id" is considered bad practice?
217
votes
14 answers

"Never do in code what you can get the SQL server to do well for you" - Is this a recipe for a bad design?

It's an idea I've heard repeated in a handful of places. Some more or less acknowledging that once trying to solve a problem purely in SQL exceeds a certain level of complexity you should indeed be handling it in code. The logic behind the idea is…
PhonicUK
  • 1,047
  • 3
  • 11
  • 12
161
votes
4 answers

why are noSQL databases more scalable than SQL?

Recently I read a lot about noSQL DBMSs. I understand CAP theorem, ACID rules, BASE rules and the basic theory. But didn't find any resources on why is noSQL scalable more easily than RDBMS (e.g. in case of a system that requires lots of DB…
ducin
  • 1,729
  • 3
  • 11
  • 7
129
votes
14 answers

Is there any technical reason why, in programming, the default date format is YYYYMMDD and not something else?

Is there any engineering reason why is it like that? I was wondering in the case of a RDBMS that it had something to do with performance, since a "YEAR" is more specific than a "MONTH", for instance: you only have one year 2000, but every year have…
lucaswxp
  • 1,379
  • 2
  • 8
  • 10
101
votes
9 answers

Is it ever okay to use lists in a relational database?

I've been trying to design a database to go with a project concept and ran into what seems like a hotly debated issue. I've read a few articles and some Stack Overflow answers that state it's never (or almost never) okay to store a list of IDs or…
linus72982
  • 951
  • 2
  • 6
  • 7
100
votes
10 answers

Why is "Select * from table" considered bad practice

Yesterday I was discussing with a "hobby" programmer (I myself am a professional programmer). We came across some of his work, and he said he always queries all columns in his database (even on/in production server/code). I tried to convince him not…
the baconing
  • 1,111
  • 2
  • 8
  • 9
99
votes
14 answers

Is it considered an anti pattern to write SQL in the source code?

Is it considered an anti pattern to hardcode SQL into an application like this: public List getPersonIDs() { List listPersonIDs = new List(); using (SqlConnection connection = new SqlConnection( …
w0051977
  • 7,031
  • 6
  • 59
  • 87
81
votes
12 answers

SQL: empty string vs NULL value

I know this subject is a bit controversial and there are a lot of various articles/opinions floating around the internet. Unfortunatelly, most of them assume the person doesn't know what the difference between NULL and empty string is. So they tell…
Jacek Prucia
  • 2,264
  • 1
  • 17
  • 15
72
votes
6 answers

Why is the Select before the From in an SQL query?

This is something that bothered me a lot at school. Five years ago, when I learned SQL, I always wondered why we first specify the fields we want and then where we want them from. According to my idea, we should write: From Employee e Select…
Cyril Gandon
  • 1,296
  • 1
  • 11
  • 17
63
votes
15 answers

Co-worker renamed all of my queries

I don't know if I should be very irritated or what. I single handedly built over 300 queries for a large database, and developed a naming convention so I could find them later. No one else in my office even knows how to build a query, but I came in…
anon
62
votes
6 answers

Is this a ridiculous way to structure a DB schema, or am I completely missing something?

I have done a fair bit of work with relational databases, and think I understand the basic concepts of good schema design pretty well. I recently was tasked with taking over a project where the DB was designed by a highly-paid consultant. Please let…
Jim
  • 1,997
  • 3
  • 20
  • 25
60
votes
16 answers

Why did SQL injection prevention mechanism evolve into the direction of using parameterized queries?

The way I see it, SQL injection attacks can be prevented by: Carefully screening, filtering, encoding input (before insertion into SQL) Using prepared statements / parameterized queries I suppose that there are pros and cons for each, but why did…
Dennis
  • 8,157
  • 5
  • 36
  • 68
58
votes
4 answers

Why is SQL's BETWEEN inclusive rather than half-open?

Semi-open (or Half-Open, Half-Closed, Half-Bounded) intervals ([a,b), where xbelongs to the interval iff a <= x < b) are pretty common on programming, as they have many convenient properties. Can anyone offer a rationale that explains why SQL's…
alex
  • 2,904
  • 1
  • 15
  • 19
1
2 3
50 51