Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
This course investigates several key database-programming concepts: triggers, stored procedures, functions, and .NET CLR (Common Language Runtime) assemblies. Author Martin Guidry shows how to combine these techniques and create a high-quality database using Microsoft SQL Server 2012. The course also covers real-world uses of the INSERT, UPDATE, and DELETE procedures, and how to build a basic web form to connect to your database.
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.
There are currently no FAQs about SQL Server: Triggers, Stored Procedures, and Functions.
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.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.