This is the third in a series of articles examining some basic concepts in Sql Server. Basic Anatomy of Sql Server, part I - What is a stored procedure? Basic Anatomy of Sql Server, part II - The unit test as part of the database What does deferred name resolution really mean? Essentially part II answered the often asked question, "why can't I SELECT from an sql stored procedure?". Because there is nothing to select from. There is an absence of the concept of a table type in sql which is necessary to realize a table. Now we ask another simple question. How is it D4 can understand the assignment of a table and a test of equality between two tables just as t-sql understands the same things between numbers: var aNewTable:= GroupByShipCountry(1) ; //Assign the table for employee 1 based //on the D4 operator from Part I to //aNewTable. var Test1:= aNewTable=GroupByShipCountry(1);//Are the two tables the same? Yes. //Now change aNewTable with an update. update (aNewTable adorn{key{Cnt,MinFrt}}) set {MinFrt:=$0.00} where ((Cnt<11) and (MinFrt<$2.50)); var Test2:= aNewTable=GroupByShipCountry(1); //Now are the two tables the same? No. select row{Test1 TestofEquality_before_Update, Test2 TestofEquality_after_Update}; TestofEquality_before_Update TestofEquality_after_Update ---------------------------- --------------------------- True False And how is it that t-sql can do with numbers what D4 does with tables: DECLARE @X Integer, @Y Integer; SET @X=5; SET @Y=10; if @X=@Y print '@X=@Y' else print '@X!=@Y' @X!=@Y The answer is obvious and simple. We can only assign values and make comparisons with variables. And we cannot do anything with a variable unless it is typed. The unit in 'unit test' is the awareness of the database of a table as a variable. To say the idea of a unit test is part of the database is to recognize that a table as a variable and its type is the only way to distinguish one table from another. The unit is the same for distinguishing among numbers and strings and tables. And it is this basic unit that sql server lacks for tables. Sql server bol describes deferred name resolution as: 'This process is called deferred name resolution because table objects referenced by the stored procedure need not exist when the stored procedure is created, but only when it is executed.' What is this really a statement of? When t-sql parses these statements: IF @X=5 PRINT '@X=5' ELSE PRINT '@X!=5' it returns the error: Must declare the scalar variable "@X". In D4 when this statement is parsed: select aNonExistentTable; it returns the same error as t-sql: Unknown identifier "aNonExistentTable". These errors are the same. Each system is aware that a variable has not been defined with a type. There is the intent at parse in each system to check that an identifier (@X, aNonExistentTable) has been appropriately defined. And where the identifier is recognized as a variable and nothing else. This intent has nothing to do with the context that surrounds the identifier. And it is this intent that lies at the heart of a relational database. A statement of just the variable results in the same error. t-sql D4 ----- ------- @X aNonExistentTable; Must declare the scalar variable "@X"., Unknown identifier "aNonExistentTable". Now these are all examples of so called t-sql deferred name resolution, there is no error raised on parsing only execution: SELECT * FROM aNonExistentTable SELECT aNonExistentTable IF aNonExistentTable=anotherNonExistentTable print 'YES' CREATE PROCEDURE theTableDoesNotExist AS SELECT * FROM aNonExistentTable Given that there is computer science and not one computer science for t-sql and one for everything else, how is it that these statements can be parsed without error? Because at parse-time if there is no concept of an identitifier as a variable there is only context to check, syntax. Absence the idea of a variable there is nothing to resolve a database object to, hence it is as if these objects/identifiers do not exist at parse-time. How bol describes deferred name resolution is a consequence of working with tables in a variable-less system. It is a price paid, in terms of sacrifice of integrity and sacrifice in management of table objects, by the developer for working in a type-less and variable-less and therefore a non-relational database. Explanations like deferred name resolution are quite common in sql but they are all just different sides of the same central issue. For example there is the issue of impedance mismatch. This is just an expression of the inherent difficulty of communication between a client, which understands what a variable is, and an sql server which does not. And finally there is the idea of relational division. Since comparisons require variables sql forces an inference to be made about a comparison of table(s) it cannot do. It forces the use of constructs that are obtuse and complex compared to simple and direct comparisons that can be made in a relational database where the table exists as a variable. (And now you know why you can't pass a table as a parameter. There is no table variable to pass ☺ . The history of sql is a history of a language trying to exist outside the mainstream of the rest of IT. It's long overdue that application development use a database that has the same foundation as other programming languages. And that kind of database is relational. Basic Anatomy of Sql Server, part I What is a stored procedure? Basic Anatomy of Sql Server, part II The unit test as part of the database. Basic Anatomy of Sql Server, part III What does deferred name resolution really mean? Some related articles of interest: All tables are typed variables A table as a parameter Reusable procedures
Dataphor SQL RAC (Relational Application Companion)
A site of hope for those looking for a true relational database system
- a one-one requirement constraint with dataphor (1)
- anatomy of sql server part I - what is a stored procedure (1)
- anatomy of sql server part II - the unit test as part of the database (1)
- anatomy of sql server part III - what does deferred name resolution really mean (1)
- censoring sql posts (1)
- creating an opposite constraint in dataphor (1)
- dataphor (2)
- Dataphor (7)
- dataphor # 13 a table as a parameter (1)
- dataphor - download and start working with it (1)
- dataphor - fixed sized word segments (1)
- dataphor # 10 sql mythology (1)
- dataphor # 11 string differences (1)
- dataphor # 12 trimming a string (1)
- dataphor # 14 sql the meaning of Update..From (1)
- dataphor # 15 views with substance (1)
- dataphor # 16 inclusive vs exclusive solutions (1)
- dataphor # 17 a visual look at ranking queries (1)
- dataphor # 18 data scrubbing using lists (1)
- dataphor # 19 create intervals over strings (1)
- dataphor # 20 browsing an sql window (1)
- dataphor # 21 an example of relational division (1)
- dataphor # 22 reusable procedures (1)
- dataphor # 23 repley to Michel (1)
- dataphor # 24 basics of the table type (1)
- dataphor # 25 extending the dense rank function (1)
- dataphor # 26 query a hierarchy with explode (1)
- dataphor # 27 combine strings with Split and Concat (1)
- dataphor # 28 constants and variables or sql and D4 (1)
- dataphor # 29 another example of relational division (1)
- dataphor #1 introduction (1)
- dataphor #2 splitting strings (1)
- dataphor #3 string concatenation (1)
- dataphor #4 comment (1)
- dataphor #5 comment (1)
- dataphor #6 formal definition (1)
- dataphor #7 sql: table this (1)
- dataphor #8 list to table (1)
- dataphor #9 table constraints (1)
- dataphor creating lists in a query (1)
- extracting numbers from a string with dataphor (1)
- jeff modens dynamic crosstabs for sql server (1)
- linq to sql the what and why (1)
- linq to sql as a window of opportunity to sql users (1)
- linq to sql should be important to sql users (1)
- linq to sql vs. older 4GL attempts (1)
- listing missing table item (1)
- Multiple cascade paths to the same table (1)
- RAC (4)
- RAC #1 comment (1)
- RAC #2 example (1)
- RAC #3 finding the Nth number in a string (1)
- RAC #4 Sql Server 2005 ranking functions vs. Rac ranking (1)
- sorting a delimited string by its numerical string parts (1)
- sql an example of extreme implicit conversions (1)
- sql can't handle complicated cascading updates (1)
- sql CTE should be a variable not a value (1)
- sql dense rank for identifying consecutive runs (1)
- sql is there really a table variable (1)
- sql ranking functions explained by relational types (1)
- sql server triggers are best set based (1)
- sql the idea of using substring to simulate lists (1)
- sql the undefined trigger in Sql Server (1)
- sql vs relational on tables (1)
- sql what the sql CTE covers up (1)
- types and procedures (1)
Tuesday, November 06, 2007
Basic Anatomy of Sql Server, part III
Subscribe to:
Post Comments (Atom)
2 comments:
Oi, achei seu blog pelo google está bem interessante gostei desse post. Gostaria de falar sobre o CresceNet. O CresceNet é um provedor de internet discada que remunera seus usuários pelo tempo conectado. Exatamente isso que você leu, estão pagando para você conectar. O provedor paga 20 centavos por hora de conexão discada com ligação local para mais de 2100 cidades do Brasil. O CresceNet tem um acelerador de conexão, que deixa sua conexão até 10 vezes mais rápida. Quem utiliza banda larga pode lucrar também, basta se cadastrar no CresceNet e quando for dormir conectar por discada, é possível pagar a ADSL só com o dinheiro da discada. Nos horários de minuto único o gasto com telefone é mínimo e a remuneração do CresceNet generosa. Se você quiser linkar o Cresce.Net(www.provedorcrescenet.com) no seu blog eu ficaria agradecido, até mais e sucesso. If is possible add the CresceNet(www.provedorcrescenet.com) in your blogroll, I thank. Good bye friend.
stacking http://blogs-new.bestfriends.org/members/Electric-Blankets/default.aspx healing http://www.netknowledgenow.com/members/Furnace-Filters.aspx eecs http://www.netknowledgenow.com/members/Vending-Machines.aspx indignation http://www.netknowledgenow.com/members/Kitchen-Cabinets.aspx waasdorp http://www.netknowledgenow.com/members/Slipcovers.aspx sadowski
Post a Comment