What does the "Structured" word means in SQL?
Is it because this(SQL) language statements are organized into Clauses, expressions and predicates?
Because of this organization, is it called "Structured" ?
The original full name was SEQUEL, which stood for "Structured English Query Language". It later had to be renamed to SQL due to trademark issues.
So basically, it was yet another attempt to sell a programming language as "just like English, except with a formal syntax" (hence "structured").
As I understand it, SQL is actually an abbreviation of SEQUEL, or Structured English Query Language. It was meant to have queries that everyone could read. The structured part means that you can only use a structured English; i.e. select col1 from table1, but not give col1 out of table1.
Mostly because it is a backronym. They needed a S to make Sequel.
from: http://wiki.answers.com/Q/Why_sql_is_called_structured_query_language
SQL, the standard that was later developed from Codd's work, provides a means of describing data with its natural structure only - that is, without superimposing any additional structure for machine representation purposes.
Related
What does the "Structured" word means in SQL?
Is it because this(SQL) language statements are organized into Clauses, expressions and predicates?
Because of this organization, is it called "Structured" ?
The original full name was SEQUEL, which stood for "Structured English Query Language". It later had to be renamed to SQL due to trademark issues.
So basically, it was yet another attempt to sell a programming language as "just like English, except with a formal syntax" (hence "structured").
As I understand it, SQL is actually an abbreviation of SEQUEL, or Structured English Query Language. It was meant to have queries that everyone could read. The structured part means that you can only use a structured English; i.e. select col1 from table1, but not give col1 out of table1.
Mostly because it is a backronym. They needed a S to make Sequel.
from: http://wiki.answers.com/Q/Why_sql_is_called_structured_query_language
SQL, the standard that was later developed from Codd's work, provides a means of describing data with its natural structure only - that is, without superimposing any additional structure for machine representation purposes.
What does the "Structured" word means in SQL?
Is it because this(SQL) language statements are organized into Clauses, expressions and predicates?
Because of this organization, is it called "Structured" ?
The original full name was SEQUEL, which stood for "Structured English Query Language". It later had to be renamed to SQL due to trademark issues.
So basically, it was yet another attempt to sell a programming language as "just like English, except with a formal syntax" (hence "structured").
As I understand it, SQL is actually an abbreviation of SEQUEL, or Structured English Query Language. It was meant to have queries that everyone could read. The structured part means that you can only use a structured English; i.e. select col1 from table1, but not give col1 out of table1.
Mostly because it is a backronym. They needed a S to make Sequel.
from: http://wiki.answers.com/Q/Why_sql_is_called_structured_query_language
SQL, the standard that was later developed from Codd's work, provides a means of describing data with its natural structure only - that is, without superimposing any additional structure for machine representation purposes.
Why did Andres Heilsberg designed LINQ syntax to be different than that of SQL (whereby made an overhead for the programmers to learn a whole new thing)?
Weren't it better if it used same syntax as of SQL?
LINQ isn't meant to be SQL. It's meant to be a query language which is as independent of the data source as reasonably possible. Now admittedly it has a strong SQL bias, but it's not meant to just be embedding SQL in source code (fortunately).
Personally, I vastly prefer LINQ's syntax to SQL's. In particular, the ordering is much more logical in LINQ. Just by looking at the order of the query clauses, you can see the logical order in which the query is processed. You start with a data source, possibly do some filtering, ordering etc, and usually end with a projection or grouping. Compare that with SQL, where you start off saying which columns you're interested in, not even knowing what table you're talking about yet.
Not only is LINQ more logical in that respect, but it allows tools to work with you better - if Visual Studio knows what data you're starting with, then when you start writing a select clause (for example) it can help you with IntelliSense. Additionally, it allows the translation from LINQ query expressions into "dot notation" to be relatively simple using extension methods, without the compiler having to be aware of any details of what the query will actually do.
So from my point of view: no, LINQ would be a lot worse if it had slavishly followed SQL's syntax.
First, choose your flavor of SQL - there are several! (T-, PL-, etc).
Ultimately, there are similarities and differences. A lot of the LINQ changes make more sense - i.e. choosing your source (FROM) before you try filtering (WHERE) / projection (SELECT), allowing better static analysis etc (including intellisense), and a more natural query comprehension syntax. This helps both the developer and the compiler, so I'm happy.
It is simpler to parse expression when initial data is provided in its beginning.
Because of this VS provides code completion even for partially written LINQ queries (great feature IMO).
The reason is the C# language designers use this approach because of when I first specify where the data is coming from, now Visual Studio and the C# compiler know what my data looks like. And I can have IntelliSense help in the rest of the query because Visual Studio will know that "city" (for example) is a string, and it has operations like startsWith and a property named length. And really, inside of a relational database like SQL Server, the select clause that you are writing in a SQL statement at the top is really one of the last pieces of the information the query engine has to figure out. Before that it has to figure out what table you are working against in the from clause even though the from clause comes later in SQL syntax
Why yes or why not?
SQL was designed as a declarative language, in sense that you tell what you want to get and the SQL engine decides how.
However, SQL operates on sets, and the results of the functions can be first class sets in Oracle, SQL Server and PostgreSQL.
One can say that SQL is functional language, as long as a function takes a set as its input and produces a set as its output.
That is, you can write something like this:
SELECT *
FROM mytable t
JOIN myfunction(x) f
ON f.col1 = t.col2
, or even this:
SELECT *
FROM mytable t
CROSS APPLY
myfunction(t.col2) f
(in SQL Server)
or this:
SELECT t.*, myfunction(t.col2)
FROM mytable t
(in PostgreSQL)
This is not a part of SQL standard, though.
Just like a C++ compiler tries to find an optimal way to multiply two floats (in terms of plain algebra), SQL optimizer tries to find an optimal ways to multiply two sets (in terms of relational algebra).
In C++, you just write a * b and rely on compiler to generate an optimal assembly for this.
In SQL, you write SELECT * FROM a NATURAL JOIN b and rely on optimizer.
However, with all SQL's declared declarativity (no pun intended), most real optimizers are able to do only very basic query rewrites.
Say, no optimizer I'm aware of is able to use same efficient plan for this query:
SELECT t1.id, t1.value, SUM(t2.value)
FROM mytable t1
JOIN mytable t2
ON t2.id <= t1.id
GROUP BY
t1.id, t1.value
and for this one:
SELECT id, value, SUM(t1.value) OVER (ORDER BY id)
FROM mytable
, to say nothing of more complex queries.
That's why you still need to formulate your queries so that they use an efficient plan (while still producing the same result), thus making SQL quite a bit less of a declarative language.
I recently made post in my blog on this:
Double-thinking in SQL
No, SQL is not a functional language. The paradigm is somewhat different. Note that there are other types of declarative programming languages other than functional - the canonical example being logic programming and PROLOG.
Technically, Relational Algebra (the theoretical basis of SQL) is not actually turing complete. Although modern SQL dialects add enough procedural features so that one can implement stored procedures and are turing complete at this level, a single SQL query is not a turing complete computation. Relational Algebra has the property of godel completeness. Godel completeness implies the ability to express any computation that can be defined in terms of first order predicate calculus - basically what you would know as ordinary logical expressions.
Are functions first-class objects in SQL? hardly. So I'd say no.
I think SQL and functional languages are very different from each other. In a functional language computation is done by evaluating functions. Functions do not mutate state. All they do is compute a value from their arguments. I other words, functions do not cause side-effects. Functional languages are general purpose.
SQL is a language designed for dealing with relational database management systems. It can be viewed as a Domain Specific Language. It is designed to work on "sets" of data. It can mutate global state (i.e, the database) by using commands like UPDATE. There is no concept of functions getting evaluated to a value. As far as I understand, SQL is not even Turing complete.
Declarative and functional? That would be a spreadsheet.
There's no single true definition of what a functional language is (or for that matter, what a procedural or object-oriented one is).
But I can't really think of much that points to SQL being functional.
It doesn't have functions, it doesn't have recursion, it doesn't have closures, it doesn't have nested functions, it doesn't have functions as first-class types.
A more commonly asked question is whether SQL is a programming language at all. It's not turing-complete.
Not generally speaking, as without extensions to the syntax (e.g. PL/SQL, T-SQL), you can't write functions.
But it is certainly very expression-oriented, which is a feature it has in common with functional languages.
In a sense: yes, SQL is functional.
Look at
SELECT as map(),
WHERE as filter(),
ORDER BY as sort(),
DISTINCT as set()
etc.
Since the point of a functional language is that you program with, well, functions, I would say no. SQL is programming with relations (if you can even call SQL a programming language - in it's basic form, SQL is not Turing complete).
I would say yes. A SQL Query maps one set of data (ie, data from tables) to another (the result set).
In mathematics, a function is basically a mapping from one set to another.
Thus, a query is a function, and since queries are first class citizens in SQL, therefore SQL is a functional language.
In just about any formally structured set of information, you start reading either from the start towards the end, or occasionally from the end towards the beginning (street addresses, for example.) But in SQL, especially SELECT queries, in order to properly understand its meaning you have to start in the middle, at the FROM clause. This can make long queries very difficult to read, especially if it contains nested SELECT queries.
Usually in programming, when something doesn't seem to make any sense, there's a historical reason behind it. Starting with the SELECT instead of the FROM doesn't make sense. Does anyone know the reason it's done that way?
I think the way in which a SQL statement is structured makes logical sense as far as English sentences are structured. Basically
I WANT THIS
FROM HERE
WHERE WHAT I WANT MEETS THESE CRITERIA
I don't think it makes much sense, In English at least, to say
FROM HERE
I WANT THIS
WHERE WHAT I WANT MEETS THESE CRITERIA
The SQL Wikipedia entry briefly describes some history:
During the 1970s, a group at IBM San Jose Research Laboratory developed the System R relational database management system, based on the model introduced by Edgar F. Codd in his influential paper, "A Relational Model of Data for Large Shared Data Banks". Donald D. Chamberlin and Raymond F. Boyce of IBM subsequently created the Structured English Query Language (SEQUEL) to manipulate and manage data stored in System R. The acronym SEQUEL was later changed to SQL because "SEQUEL" was a trademark of the UK-based Hawker Siddeley aircraft company.
The original name explicitly mentioned English, explaining the syntax.
Digging a little deeper, we find the FLOW-MATIC programming language.
FLOW-MATIC, originally known as B-0 (Business Language version 0), is possibly the first English-like data processing language. It was invented and specified by Grace Hopper, and development of the commercial variant started at Remington Rand in 1955 for the UNIVAC I. By 1958, the compiler and its documentation were generally available and being used commercially.
FLOW-MATIC was the inspiration behind the Common Business Oriented Language, one of the oldest programming languages still in active use. Keeping with that spirit, SEQUEL was designed with English-like syntax (1970s is modern, compared with 1950s and 1960s).
In perspective, "modern" programming systems still access databases using the age old ideas behind
MULTIPLY PRICE BY QUANTITY GIVING COST.
I must disagree. SQL grammar is not inside-out.
From the very first look you can tell whether the query will SELECT, INSERT, UPDATE, or DELETE data (all the rest of SQL, e.g. DDL, omitted on purpose).
Back to your SELECT statement confusion: The aim of SQL is to be declarative. Which means you express WHAT you want and not HOW you want it. So it makes every sense to first state WHAT YOU WANT (list of attributes you're selecting) and then provide the DBMS with some additional info on where that should be looked up FROM.
Placing the WHERE clause at the end makes great sense too: Imagine a funnel, wide at the top, narrow at the bottom. By adding a WHERE clause towards the end of the statement, you are choking down the amount of resulting data. Applying restrictions to your query any place else than at the bottom would require the developer to turn their head around.
ORDER BY clause at the very end: once the data has gone through the funnel, sort it.
JOINS (JOIN criteria) really belong into the FROM clause.
GROUPING: basically running data through a funnel before it gets into another funnel.
SQL sytax is sweet. There's nothing inside out about it. Maybe that's why SQL is so popular even after so many decades. It's rather easy to grasp and to make sense out of. (Although I have once faced a 7-page (A4-size) SQL statement which took me quite a while to get my head around.)
It's designed to be English like. I think that's the primary reason.
As a side note, I remember the initial previews of LINQ were directly modeled after it (select ... from ...). This was changed in later previews to be more programming language like (so that the scope goes downwards). Anders Hejlsberg specifically mentioned this weird fact about SQL (which makes IntelliSense harder and doesn't match C# scope rules) as the reason they made this decision.
Anyhow, good or bad, it's what it is and it's too late to change anything.
The order of the clauses in SQL is absolutely logical. Remember that SQL is a declarative language, where you declare what you want and the system figures out how best to get it for you. The first clause is the select clause where you list the columns that you want in the result table. This is the primary purpose of the query. Having stated what you want the result to look like, you next state where the data should come from. The where clause limits the amount of data being returned. There is no point in thinking about how to limit your data unless you know where it comes from, so it goes after the from clause. The group by clause works with the aggregation operators in the select clause and could go anywhere after the from clause however it is better to think about aggregation on the filtered data, so it comes after the where clause. The having clause has to come after the group by clause. The order by clause is about how the data is presented and could go anywhere after the select.
It's consistent with the rest of SQL's syntax of having every statement start with a verb (CREATE, DROP, UPDATE, etc.).
The major disadvantage of having the column list first is that it's inconvenient for auto-complete (as Hejlsberg has mentioned), but this wasn't a concern when the syntax was designed in the 1970s.
We could have had the best of both worlds with a syntax like SELECT FROM SomeTable: ColumnA, ColumnB, but it's too late to change it now.
Anyhow, SQL's SELECT statement order isn't unique. It exactly matches that of Python list comprehensions:
[(rec.a, rec.b) for rec in data where rec.a > 0]
History of the language aside (although it is fascinating) I think the thing you are missing is that SQL isn't about telling the system what to do, so much as what end result you want (and it figures out how to do it)
saying 'go over there to that rack, pick up the hats with hatbands, blue hats first, then green, then red, and bring them to me' is very much telling the system how to do what you want. it's programmer think where we presume the worker is very stupid and needs minutely detailed instructions.
SQL is starting with the end result first, the data you want, the order of the columns, etc.. it's very much the perspective of someone who is building a report. "I want firstname, lastname, then age, then....." That is after all the purpose of making the request. So it starts with that, the format of the results you want. Then it goes into where you expect it to find the data, what criteria to look for, the order to present it, etc.
So as an alternative to specifying in minute detail what you want the worker to do, SQL presumes the system knows how to do that, and centers more on what you want.
So instead of pedantically telling your worker to go here, get this, bring it over there.. it's more like saying "I want hats, from rack 12, which have hatbands, and please sort them by color."