Now that we've seen how to create a stored procedures using T-SQL and how to create stored procedures using C#, you're going to be faced with a decision. Every stored procedure you create, you have to choose either T-SQL or C#. I'd like to give you some tips on which one to use. There's very little that can be done and one that can't be done in the other. If you try hard enough, you can accomplish anything with either one. But each one does have its stress and its weaknesses. T-SQL's strength is certainly querying data.
We can just go in there and directly write a SELECT, UPDATE, INSERT or DELETE statement. You don't have to set up a connection, don't have to close a connection. We just write our T-SQL statements and they run. T-SQL however, is poor with complex logic. We have very few decision structures. Basically, you've an if, and not a whole lot of else, and we have a very few looping structures. You have a while, and not a whole lot else. T-SQL does not natively support, arrays, collections, for-each or classes, and all of those are things that the typical programmer wants.
The .NET languages, their weakness is querying data and it's not super difficult to query data, but you're going to have to write approximately 3 to 5 lines of code to set up a connection, and then every time you want to use that connection, you should manually open the connection, and manually close the connection. So it's placing some administrative overhead on the developer. The .NET however, is very robust with looping and control of flow. We've lots of great looping structures, lots of great decision structures in all of the .NET languages.
And the .NET languages can be compiled for multiprocessor environments and will run much faster and much more efficiently in a multiprocessor environment. So when making this choice, Microsoft has clearly stated repeatedly that you should use T-SQL for any stored procedure where the primary focus is data access. However, if you have complex logic or a CPU intensive function, they recommend the .NET framework. I certainly agree with both of those recommendations.
I'll go ahead and add a third one, but you also have to think about human resources, the people that are writing the program, if they are much stronger in T-SQL, or much stronger in C#, obviously, that's going to influence your decision. But if your team of developers has approximately the same level of experience with both, then certainly these are valid ways to make the choice. T-SQL for data access and .NET for complex logic.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98365 Viewers
61 Video lessons · 85659 Viewers
71 Video lessons · 69596 Viewers
56 Video lessons · 101918 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Your file was successfully uploaded.