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.

765 questions
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
  • 16
  • 19
54
votes
7 answers

SQL Triggers and when or when not to use them.

When I was originally learning about SQL I was always told, only use triggers if you really need to and opt to use stored procedures instead if possible. Now unfortunately at the time (a good few years ago) I wasn't as curious and caring about…
nyxthulhu
  • 651
50
votes
3 answers

Why is most SQL written in YELLING?

On MySQL at least, the following two queries are functionally identical: select * from users limit 0, 1000; SELECT * FROM users LIMIT 0, 1000; However, most example sites and most developers I've worked with use the latter, while I prefer the…
Naftuli Kay
  • 1,621
  • 2
  • 16
  • 23
32
votes
11 answers

Why is prefixing column names considered bad practice?

According to a popular SO post is it considered a bad practice to prefix table names. At my company every column is prefixed by a table name. This is difficult for me to read. I'm not sure the reason, but this naming is actually the company…
32
votes
11 answers

Is there any material difference between queries joined by WHERE clauses, and queries using an actual JOIN?

In Learn SQL the Hard Way (exercise six), the author presents the following query: SELECT pet.id, pet.name, pet.age, pet.dead FROM pet, person_pet, person WHERE pet.id = person_pet.pet_id AND person_pet.person_id = person.id AND …
Robert Harvey
  • 199,517
28
votes
6 answers

Why SQL is not so widespread in large desktop applications?

As a software developer, I've worked on projects ranging from tiny home-made apps to medium-size enterprise applications. In nearly every project I used a database or regretted choosing not to use it from the beginning. Now, I am wondering a few…
10
votes
12 answers

How is "SELECT *" read in English?

The other day, a friend told me that in USA, they pronounce SQL like squel, not es-qu-el. I was surprised. I was wondering how "SELECT *" is read/pronounced while talking. select star? select asterisks? select all?
nimcap
  • 613
6
votes
6 answers

Confusion about proper use of * wildcard in SQL

Suppose I was writing an address book application where the details of each contact were stored in an SQL database. A user wants to know all the details for a person whose name is "Bob [Someone]". In such a case, would writing a query like this be…
W.K.S
  • 236
5
votes
2 answers

Does it make sense to use a cursor for complex business logic?

I am dealing with a pretty extensive data set. After a few joins, the foundation table has something like 40 columns. The next 40 columns will all be calculated. I am trying to keep my Java clean of the business logic because it is fairly verbose,…
mike
  • 161
4
votes
4 answers

Multiple Joins or Simple Readable Database Calls

Curious how other developers feel about this. I come across some pretty nasty sql joins, as we all do I'm sure. I would prefer making more database calls for the sake of readability and simplicity rather than have a large SQL statement to maintain;…
3
votes
3 answers

Managing database schema for a C++ app

I have an open source project (Cockatrice) that uses mysql for the server component. I'm planning some changes to the schema, but right now the only management I have is a script that runs the proper CREATE TABLE statements. Before I start rolling…
Daenyth
  • 8,127
1
vote
1 answer

Sql Server string Prefix doubt

I'm learning T-SQL. Why the strings are prefixed with N in every example I've seen? What are the pros or cons of using this prefix? Please make it clear that if my column has datatype as nvarchar /vachar then is it mandatory to provide values using…
1
vote
2 answers

Using a masterID in sql to merge different item types

I am designing tables in sql for a small ticketing system. One of the demands is that a user/agent can post a ticket to either a department or an agent. Now if I have a child parent table where each agent belongs to one department, I would end up…
John
  • 773
1
vote
1 answer

What is better: multiple sql entries or one sql entry with a list field?

Suppose that I have the following logical information: (tag_name, id). For example: (food, 1),(food, 2),(food, 3),(drink, 1),(drink, 2) I'm trying to decide what is the best way to store it in a database. I can simply use a (STRING, INTEGER) table…
EpsilonVector
  • 10,763
0
votes
1 answer

Splitting 1-1 relationships across lots of different tables?

I've come across a table that has about 200 columns. About 150 of these can be grouped into 5-10 tables that make real world "sense", and seeing as most of these entries are never used I figured it would save a lot of null pointers and reduce the…
1
2