March 13, 2009 at 3:29 pm
foxjazz (3/13/2009)
ok example sort of (my computer is sick so I can't give you something already done)select name from mynametable where changedate > @yesterday
fetch from @sel into @name
while (@@fetch_status = 0)
begin
insert into nameother (name,changeddate) values (@name,getdate())
end
Do this without a cursor!
Sure:
insert into nameother (name, changeddate)
select
name,
getdate()
from
mynametable
where
changedate > dateadd(dd,datediff(dd,0,getdate()),-1);
Of course its untested as i didn't bother to create any tables for this.
March 13, 2009 at 3:33 pm
March 13, 2009 at 3:41 pm
foxjazz (3/13/2009)
ok example sort of (my computer is sick so I can't give you something already done)select name from mynametable where changedate > @yesterday
fetch from @sel into @name
while (@@fetch_status = 0)
begin
insert into nameother (name,changeddate) values (@name,getdate())
end
Do this without a cursor!
So the problem is really just the fact that you don't know the basics of TSQL.
You need to take the time to actually learn SQL:
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
And the primary Microsoft SQL Server References:
SQL Server 2000 Books Online
http://msdn2.microsoft.com/en-us/library/aa257103(SQL.80).aspx
SQL Server 2005 Books Online
March 13, 2009 at 3:45 pm
foxjazz,
You seem to be frustrated with T-SQL, but it appears that a lot of your complaints are just ignorance in how the language works. You example is one of the trivial things T-SQL can do and it's something that people unfamiliar with the language would struggle with.
Why would someone that uses C# expect T-sql to just work from the IDE? Do you expect that you can use Java as well from there? There is a learning curve in growing to use a different platform? Do you expect that the Sharepoint SDK just be understood because you learned how to manipulate Excel files?
Please also understand that we have professionals here. Insulting others isn't something we want to see, and isn't tolerated. If you can't have a rational discussion, I'll have to remove your account. Remember this also reflects on your career. Comments like that one (if I found it Googling you), would make me think twice about granting you an interview.
March 13, 2009 at 3:48 pm
From my point of view both languages differ since their "parents" were developed for different use:
As per Wiki
"C was designed for writing architecturally independent system software, it is also widely used for developing application software."
whereas SQL has been
"designed for the retrieval and management of data in relational database management systems (RDBMS)"
Both have improved a lot for the purpose they were intended to be used - and both a lacking the comfort of the other:
As far as I know T-SQL is not the best language to be used for a frontend development and C# probably has a hard time dealing with a huge amount of data in terms of storage, accessing, and performance (regardless whether you call it set's or object's...).
My personal goal is getting the right information as fast as possible in any meaningful combination that's needed. Even if the result is shown as a plain list - to me it's still the information that counts, not the presentation around it...
But as soon as it comes to presenting the data to the public, an application/presentation layer is needed. That's the point, where C# and the like should take over.
Btw: Both languages can communicate very well e.g. via stored procedures: you can call them from C# like functions: call the function with the proper arguments and you'll get the result. Just let the SQL folks handle the data - it's more efficient for both sides (the system "behind the screen" and the programmer/developer in front of it)...
Both languages are tools in a tool belt - it's harder to knock in a nail with a screwdriver than with a hammer. And both tools have to be used in different ways as well - it won't help that much if you just twist the hammer...
I don't think there will be a unified language in the near future that will cover both (data management and presentation) by still providing the advantages of each separate language currently available.
Until such a language shows up (and gets accepted by the public), T-SQL folks depend on a separate presentation software as well as C# folks will need some assistance to reduce the huge amount of information we are faced with today to a presentable volume. At least from my point of view.
Ending that rather long monologue:
If you request us to provide you a C#-like T-SQL language or a compiler: I don't think we can help you.
If you are faced with a SQL data access/modification/performance issue where you'd like to have the opinion of somebody who's more familiar with that kind of an issue that's most probably the right place to ask - but you didn't ask yet.
And if you opened up that thread just because you don't like T-SQL, I don't see any point in time where we can give you any information you are satisfied with.
So, what exactly is your point/question for opening that thread? Without knowing that, it's really hard to help you...
March 13, 2009 at 3:58 pm
foxjazz,
I believe I met your requirement. We all are still waiting to hear back from you.
March 13, 2009 at 3:59 pm
First off, I don't "struggle" with t-sql, I use it a lot.
A lot of what I have to do is use cursors, because of how my database is structured, and the types of items I need to have updated or changed.
Most of the time when using cursors, it isn't to go through lots of records, but just a few at a time.
I frequently go from c# to t-sql language throughout the day.
For a specific problem without the use of a cursor gee I use a c# datatable. Isn't that quant.
It isn't insulting to critisize a product because it deserves criticism. And the fact that they slightly improved on the language in 2008 justifies this case.
The fact that Microsoft is trying to make things easier with LINQ, and other tools and technologies has really been very refreshing. But t-sql still gets NO recourse.
And you guys that advocate it not changing, because it could be a lot better with language preference options, and maybe some intellisense added don't win any awards in my book.
The fact that it could be a better platform to manage data in (and yea I guess I could use sql clr) but why go to all that trouble.
Microsoft found it fit to put service broker in sql, which is really kinda nice even though some hoops have to be done to get it working.
t-sql or script writing under managment studio could easily be made better. And currently it's the only crappy language I am forced to deal with because most of you guys can't see further than you want to.
March 13, 2009 at 4:02 pm
foxjazz (3/13/2009)
Another point, why should someone that knows c# or vb and does it daily, have to learn t-sql.Why can't t-sql accomadate that flavor of language just like the IDL compiler does for .net languages.
WHY DO YOU HAVE TO GET USE TO IT?
Because that is what professionals do. They do not bemoan irrelevant issues of style that were decided long ago, or try to blame the world for their own unwillingness to learn more than one language (or language style) competently. Professionals will learn to use the tools that they have available to do the best job that they can.
Thats' just a cop out.
No, your complaints are a cop-out for someone who does not want to have to learn something new well enough that they can be comfortable in it. In my career I have professionally worked in over 20 different languages encompassing at least a half-dozen major language styles (note: C, C#, C++, Java, and Javascript are all one style). If you want to be a professional in this field, then you should be prepared to do the same.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
March 13, 2009 at 4:05 pm
foxjazz (3/13/2009)
First off, I don't "struggle" with t-sql, I use it a lot.A lot of what I have to do is use cursors, because of how my database is structured, and the types of items I need to have updated or changed.
Most of the time when using cursors, it isn't to go through lots of records, but just a few at a time.
I frequently go from c# to t-sql language throughout the day.
For a specific problem without the use of a cursor gee I use a c# datatable. Isn't that quant.
It isn't insulting to critisize a product because it deserves criticism. And the fact that they slightly improved on the language in 2008 justifies this case.
The fact that Microsoft is trying to make things easier with LINQ, and other tools and technologies has really been very refreshing. But t-sql still gets NO recourse.
And you guys that advocate it not changing, because it could be a lot better with language preference options, and maybe some intellisense added don't win any awards in my book.
The fact that it could be a better platform to manage data in (and yea I guess I could use sql clr) but why go to all that trouble.
Microsoft found it fit to put service broker in sql, which is really kinda nice even though some hoops have to be done to get it working.
t-sql or script writing under managment studio could easily be made better. And currently it's the only crappy language I am forced to deal with because most of you guys can't see further than you want to.
And I will bet you dollars for donuts that most of the time that you are using cursors there is a set based solution as well, you just haven't taken the time to figure it out.
I am more than a DBA. I am also a developer and I have worked in other languages. It just takes time to learn the new paradigms when changing languages.
T-SQL and C# are written for two different things and require different mindsets to work in them efficiently.
March 13, 2009 at 4:27 pm
foxjazz,
Are Matt's and Lynn's code examples shorter than you C# code?
Definitely.
Do they do the task?
Absolutely.
What about performance?
Try it and see - C# won't see the dust tail after TSQL.
Does it mean C# sucks?
You bet.
P.S. I heard rants like yours about SQL from many developers.
And by some coincidence they all appear amongst the worst ones.
_____________
Code for TallyGenerator
March 13, 2009 at 4:28 pm
Ok here is what I would like to do:
run a query or view that gets a datatable (in t-sql) not c#
Then run through each record in the datatable that I have, and assign values to insert or update statements at my liesure.
That is what I would like it to do. Should be easy right?
And I don't want to have to use cursors to do it.
Hey Fox,
Whenever dealing with a "new" language (new meaning new to me), I have learned that the designers had certain things in mind when they created it. Whenever I find myself struggling with the language, it's usually because I'm not quite getting how the designers want me to use the language.
In the quote above, you set up the problem in a way that is intuitive to most coders out there. You want to grab a bunch of records, then go through them one at a time and make a decision about what to do with each one. It's a loop: Read a row. Test some values. Write or update. Repeat.
This is what is known as procedural coding. What you need to understand about T-SQL is that it is not intended to be a procedural language. It has a few constructs, like cursors and while loops that support it, but they are generally discouraged. Here's why.
The database engine is like an automatic transmission for data storage and retrieval. It makes decisions for us based on it's superior knowledge of the current statistics in the indexes for each table. It is most efficient when dealing with entire sets of data. In set-based programming, you don't WANT to loop through a set one row at a time. That is like forcing your automatic transmission into low gear. Yes, you have total control, but your car is going to slow to a crawl. Better to just keep your hands on the wheel and let the automatic transmission take care of itself.
In T-SQL we try for set-based solutions. Rather than grabbing a set and going through it a row at a time, we use T-SQL to send the database engine instructions about what to do with the entire set. So in SQL, we use the CASE expression with a single UPDATE a lot more than using WHILE loops and IF statements to drive a series of individual UPDATES. We do this because IF tests a single value and CASE operates against every row in a set. CASE Statements are easy, and so are things like inline table valued functions. You just are still waiting on that moment when the light goes on and you go "AH-HAH! THAT's how you do it." There are no mysteries you can't eventually decipher, if you want to.
You have to learn to let go a little, because the database engine/query optimizer really does know better than you (or me) how to get it done quickly. The game is more complex than just executing instructions to change values in a page of memory. If we tried to manually handle all the paging, buffering, and disk I/O that the database handles for us, we'd never get much productive work done. But when you quit trying to fight it and work with it, it is FAST.
You sound like a bright guy, so open yourself up to the different concepts. Once you understand, or accept, what SQL is designed for then you will realize that it is like nothing else in your programming experience. There is a reason relational databases are at the heart of most systems, even though hierarchical databases are faster.
You're not going to convince everyone here that T-SQL sucks. Your arguments just show that you don't truly understand the concept yet. The good news is that if you want to learn the hows and whys of relational databases and SQL, you have stumbled onto a motherlode of people who would be happy to help you. (Of course that may not be as much fun as trolling and picking a fight. Did you try this argument out in other SQL forums?) Anyway, I hope you join our little club.
Regards,
Bob
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 13, 2009 at 4:30 pm
foxjazz (3/13/2009)
First off, I don't "struggle" with t-sql, I use it a lot.
I can imagine how it suffers.
:pinch:
My condolences to poor T-SQL.
:crying:
😛
_____________
Code for TallyGenerator
March 13, 2009 at 4:31 pm
foxjazz (3/13/2009)
It isn't insulting to critisize a product because it deserves criticism. And the fact that they slightly improved on the language in 2008 justifies this case.
No it isn't. What was insulting was this comment:
foxjazz (3/13/2009)
Gee lynn are you dense. Do I have to write it in t-sql for you to get it?I don't like cursors.
wtf
I have reread all the posts, and I can't find anything where we were unprofessional in our responses to your comments.
I showed you how to turn a cursor based process into a set based process. It took me about 5 minutes including the cutting and pasting between SSMS and IE to post the code back for you. Have you said anything regarding the code, like "wow, you can do it without using a cursor."
I'd be willing to look at some of your other code and see what could be done to eliminate cursors in your code.
March 13, 2009 at 4:40 pm
foxjazz (3/13/2009)
--------------------------------------------------------------------------------
Gee lynn are you dense. Do I have to write it in t-sql for you to get it?
I don't like cursors.
wtf
Hey Lynn: Ask him if he likes CTEs. 😎
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
March 13, 2009 at 8:40 pm
Fox, You actually use a cursor for that kind of operation??? :crazy:
-Roy
Viewing 15 posts - 31 through 45 (of 465 total)
You must be logged in to reply to this topic. Login to reply