August 23, 2011 at 1:02 am
Hi All,
I have recently read about Procedural language and Declarative language. I need a classical SQL example for both the procedural and Declarative language.
Can i say CURSOR is the example for Procedural?
Inputs are welcome!
karthik
August 23, 2011 at 1:21 am
Did you heared that in T-SQL for Sql Server 2005.
As of now I know only Procedural Language in T-SQL.
Dividing the complex logic into small small parts and keep that in a procedure and call that procedure in out complex logic.
what do you mean by Declaritive language with respect to T-SQL.
August 23, 2011 at 5:07 am
Prassad Dabbada V R (8/23/2011)
Did you heared that in T-SQL for Sql Server 2005.As of now I know only Procedural Language in T-SQL.
Dividing the complex logic into small small parts and keep that in a procedure and call that procedure in out complex logic.
what do you mean by Declaritive language with respect to T-SQL.
T-SQL is based in SQL which is Declaritive language, example:
SELECT * FROM Table
T-SQL is still mostly declaritive and should be used as it as much as possible.
However it is extened to have functional capabilities of Procedural Language (PL\SQL is the example of such).
Example of procedural coding in T-SQL would be using any kind of cursors (eg. loops):
WHILE (Something <> OtherSomething)
BEGIN
... Do something ...
END
or
DECLARE cursor CURSOR...
...
WHILE ... (see the procedural loop again)
Also procedural example could be as simple as following:
DECLARE @var INT
DECLARE @var2 INT
SET @var2 = @var + something
SET @var = Something +@var2
August 23, 2011 at 5:59 am
Thank you very much, it is very clear now.
August 24, 2011 at 12:20 am
Procedural program - some series of computational steps to be carried to solve a problem.
Declare @id int
select @id = id from emp where eno = 5
can we say it as a procedural code?
karthik
August 24, 2011 at 2:16 am
karthikeyan-444867 (8/24/2011)
Procedural program - some series of computational steps to be carried to solve a problem.Declare @id int
select @id = id from emp where eno = 5
can we say it as a procedural code?
Is this some sort of assignment? Eugene's answer seems accurate & comprehensive enough to me. With SQL Server, it's a bit of a mix & therefore a bit of a grey area - so I don't think you'll ever need to state: "This is my procedural bit" etc etc.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 24, 2011 at 2:51 am
karthikeyan-444867 (8/24/2011)
Procedural program - some series of computational steps to be carried to solve a problem.Declare @id int
select @id = id from emp where eno = 5
can we say it as a procedural code?
It's procedural. You cannot see it clearly because it's incomplete.
As it looks now it is useless. @id will need to be used. It can be returned:
RETURN @id
or it may participate in some functional condition like:
IF @id > ....
Now, if you add above examples to your bit, you can see clearly.
You can say, that you just want to return selected @id as recordset (eg. SELECT @id)
Then, it would wrong usage of procedural capabilities of T-SQL as proper way would just:
SELECT id FROM emp WHERE eno = 5
Saying that doesn't mean that you should never preselect values into variables before returning them in recordset. There are more complex examplel where this technique is totaly justified. So, procedural capability is a beauty of T-SQL which makes it very powerfull tool to manipulate with data in SQL Server.
August 24, 2011 at 3:38 am
procedural capability is a beauty of T-SQL which makes it very powerfull tool to manipulate with data in SQL Server.
I got confused...could you pls refer the below link?
Joe Celko has mentioned something like below in his article.
I have spent many years trying to persuade people to use declarative rather than procedural code in SQL. One of my books is THINKING IN SETS, with the oversized subtitle "Auxiliary, Temporal, and Virtual Tables in SQL" to explain what topics are covered. Most programmers discover that it is too big a big leap from a procedural mindset to a declarative mindset, and so don't quite make the transition all at once. Instead they evolve from a procedural paradigm to a variety of semi-procedural programming styles.
karthik
August 24, 2011 at 3:48 am
'Thinking In Sets' is the important phrase.
Non-SQL developers tend to write sub-optimal SQL as a result of their general tendency towards row-by-row processing, something which SQL developers tend to avoid by instinct.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 24, 2011 at 4:18 am
karthikeyan-444867 (8/24/2011)
...
Joe Celko has mentioned something like below in his article.
...
That was bad idea to bring theoretical fanatics into our nice discussion :hehe:
Sorry, but I'm not big fan of him...
T-SQL main feature is bringing functional/procedural capabilities into decalarative SQL language. It's analogue of Oracle PL\SQL.
Someone may like or dislike anything, however from practical point of view, procedural capabilities of T-SQL are very usefull and when used appropriately they allow to solve many data-transformation tasks in a very elegant way. Also, they create possibilty of managing and administring SQLServer databases using its own language from within itself 😀
Actually I have just recent example: http://www.sqlservercentral.com/Forums/Topic1162947-392-2.aspx
There you can find solution for the given task. Procedural implementation is elegant and fully appropriate for the given task where all operations are required for a single value not for a set.
Same problem can be solved in decalarative way (example of it also is there), which doesn't look much more messy.
August 29, 2011 at 3:41 am
sorry..since i read that article, i just got confused. Thats why i brought the same here for reference...
I have gone through that post. I have to go back and read it once again..Because I missed some points in page #2.
karthik
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply