Blog Post

Database Fundamentals #11: Why Learn T-SQL

,

If you’ve been following along with the previous 10 Database Fundamentals blog posts, you have a SQL Server installed and a database with a table in it. You may have more if you’ve been practicing. Now would be the time to start adding data to the database, but first, I want to talk about the importance of T-SQL

Why T-SQL?

The way SQL Server accepts information is very different than most programs you’re used to using. Most programs focus on the graphical user interface as a mechanism for enabling data entry. While there is a GUI within SQL Server that you can use for data entry, and I will do a blog post on it, the primary means of manipulating data within SQL is the Transact Structured Query Language, or T-SQL.

T-SQL is a very rich and complex scripting language offering you a great degree of flexibility in how you use it. Because of this, you can really think of it almost like a programming language. For example, it’s very easy to glance down into the corner of your computer screen and see the date and time on display there. You could simply look down at the date and time every time you needed to enter this information and use the GUI provided by SQL Server to store that in your tables. But, that time doesn’t display seconds and it doesn’t display fractions of a second, and even if it did, you couldn’t really say that you entered a piece of data into the system at a particular fraction of a second because the time it would take to type that would make that information invalid.

Instead, you’re going to take advantage of the methods and structures offered to you by T-SQL so that you can build a script. In order to get the date and time, just as an example, the script would use the GETDATE() function so that you didn’t have to type these values into the system. GETDATE() will get the system date and time for you, and put it into the column that you told it to within your TSQL statement. You could even get more fancy (or more precise, depending on your point of view and the needs of your business) and use GETUTCDATE() to get the Universal Time Code value for the current data and time.

This is just one, rather small, example of why scripting your data access is much better than relying on the GUI. There are lots of others. For example, what if you needed to move several rows of information into the system and that information was already partly in another table in the database. You can combine data manipulation statements with data selection statements in order to move that information all at once. This is something that would take hours, maybe days, to do by hand, typing .

Also, while you do have a GUI for manipulating data within SQL Server, all that GUI is doing is generating the same T-SQL statements that you could have written on your own, except that it can’t take advantage of the functions or batch processing that is available to you through T-SQL.

For all these reasons, while I will show you how to manipulate information using the GUI provided by Microsoft, the majority of my time will be focused on the T-SQL methods for manipulating this data. I strongly encourage you to spend the time to learn T-SQL .

You can learn just about everything you’ll ever need from the SQL Server Technical Documentation, but for more, I suggest Itzik Ben Gan’s excellent book “T-SQL Fundamentals.”

Conclusion

Avoid the crutch of the GUI entirely and you’ll benefit from a great deal more functionality and ability to manipulate the data in your system. Several of the following blog posts in the series focus on various aspects of T-SQL from INSERT to SELECT to UPDATE and DELETE. We’ll get all the fundamentals covered.

The post Database Fundamentals #11: Why Learn T-SQL appeared first on Grant Fritchey.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating