Posted By: Shining Arcanine | Oct 6th @ 12:12 PM
page 1 of 1
Comments: 6 | Views: 699
Is SQL turing complete with stored procedures? More interestingly, is SQL turing complete without stored procedures? Also, is/should SQL be considered a computer programming language?

I am curious about this as the answer to the last question will determine whether I know 7 computer programming languages or 8. Specifically, I know PHP, SQL, SML, C, C++, Java, Assembly and Fortran. That is approximately the order in which I learned them, although I learned some languages simultaneously and others took longer to learn than others. Also, I am considering both x86 assembly and MIPS assembly to be the same language.
Sven Groot
Sven Groot
You can't have everything; after all, where would you put it?
I think you need to rephrase your question a bit. Stored procedures don't really have anything to do with it.

SQL as such (i.e. the SQL92 standard) is not turing complete. However, many of the languages derived from SQL, such as Oracle's PL/SQL and SQL Server's T-SQL and others are turing complete.

PL/SQL and T-SQL certainly qualify as programming languages, whether SQL92 itself qualifies is open for debate. Some people claim that any piece of code that tells a computer what to do qualifies as a programming language; by that definition SQL92 is one, but so is e.g. HTML. The definition is rather vague, and it's imo a pointless thing to argue about.

Fun fact: C++ templates provide a turing complete language, which is executed at compile time, such as the following code which computes the greatest common divisor at compile time (not run time):
template<int x, int y>
struct gcd 
{
    static const int Value = gcd<x, x % y>::Value;
};

template<int x>
struct gcd<x, 0> 
{
    static const int Value = x;
};

Big Smile
evildictaitor
evildictaitor
How could you use the adjective "indescribable" truthfully?
You are a bad bad man, Sven.

Also I would argue that number of languages known is a fairly bad assessment of the quality of the programmer. Number of different paradgms of coding, perhaps, or total years of experience programming; but fluency in one or two computer languages is much more important.

For example, you say MIPS assembly, but if I asked you to write a general matrix multiplier in it, would you be able to?
Sven Groot
Sven Groot
You can't have everything; after all, where would you put it?
By the way, would MySQL 5.0 be considered a programming language

By whom? Like I said, there are about as many definitions of what constitutes a programming language as there are programmers. The distinction is completely meaningless in the real world.
evildictaitor
evildictaitor
How could you use the adjective "indescribable" truthfully?
For __cdecl it's 

push ebp
mov ebp, esp
add esp (size of stack)
...

...
pop ebp
ret

where arguments are pushed and cleaned by caller. The 'n'th argument is on [esp + 4*(n+1)] and the 'n'th local is on [esp - 4*n], assuming all locals are sizeof(void*) long. __cdecl also has the restriction that it returns on EAX and does not modify EBX, ESP, EBP, EIP or EFLAGS over the function call. All other registers are saved by the caller if it cares about their value.

Also, by the general formula for matrix multiplication don't you just mean A : R[n,r], B : R[r,m] --> (AB) : R[n,m],  (AB)[i,j] = Sum[ i : [0, r], A[i,r] * B[r, j] ]?

With regards to whether or not it's a programming language - most people don't use Turing Completeness as a requirement (nessisary _or_ sufficient) for a syntax to be a programming language. The requirement is usually just the slightly subjective question of whether you can perform and automate meaningful tasks via the syntax. Languages for which is theoretically, but not in practise true, such as BrainF*ck and Shakespeare Programming Language are termed "esoteric programming languages", although strictly one ought to refer to them as esoteric syntaxes, since they arn't in practise used for programming. Under such a definition SQL is clearly a programming language.

It is important to remember that being good at two or three languages is much more important than having a brief overview of ten different ones - so if you feel that you know 7 or 8 programming languages, then you should probably be seeking to become really good at one or two of them (preferably in entirely different paradgms, such as learning C, C# and Haskell), rather than learning any more.