{"id":338,"date":"2017-04-07T11:43:00","date_gmt":"2017-04-07T16:43:00","guid":{"rendered":"https:\/\/www.onlc.com\/blog\/?p=338"},"modified":"2022-11-23T17:02:55","modified_gmt":"2022-11-23T22:02:55","slug":"basic-t-sql-tutorial","status":"publish","type":"post","link":"https:\/\/www.onlc.com\/blog\/basic-t-sql-tutorial\/","title":{"rendered":"Basic T-SQL Tutorial"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">T-SQL or Transact Structured Query Language is a programming language for databases. Most of the major database systems such as Oracle, Microsoft SQL Server and MySQL, utilize some form of T-SQL. It\u2019s essentially a language that lets you quickly and easily do almost anything that you would ever want to do with a database. Let\u2019s go over some of the <\/span><a href=\"https:\/\/www.onlc.com\/outline.asp?ccode=xsql01\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">basic T-SQL<\/span><\/a><span style=\"font-weight: 400;\"> commands that are available and what they do.<\/span><\/p>\n<h2><b>CRUD Operations<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">CRUD (Create, Read, Update and Delete) Operations are the basic data functions that you will most likely need to perform in any programming language. Let\u2019s break each one of these down as it pertains to T-SQL.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>CREATE <\/b><span style=\"font-weight: 400;\">does exactly what it says. It creates new objects. For instance, you can create a new database [ CREATE DATABASE ], then create new tables [ CREATE TABLE ] inside the database, then create columns [ CREATE COLUMN ] inside the tables. After the create statements have been executed to build your table structure, you can now create new data. However, you will use the INSERT statement to add data to the tables that you have created by specifying the columns that you will be inserting data into and then the data that you would like to insert. For example, [ INSERT INTO NewTable (column1, column2) VALUES (1,2) ].<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><b>READ <\/b><span style=\"font-weight: 400;\">statements are performed in T-SQL by using SELECT statements. You simply specify the columns that you would like to read and the table where they are contained. You can also filter, sort, group and perform other operations on the data to return exactly the data that you are looking for by adding a WHERE, GROUP BY and\/or ORDER BY clauses to the SELECT statement. For example, [ SELECT column1, column2 FROM NewTable WHERE column1 = 1 GROUP BY column1, column2 ORDER BY column1, column2 ]. This statement selects column one and column two from the new table and then filters, groups and sorts the data all in one statement.<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><b>UPDATE <\/b><span style=\"font-weight: 400;\">statements are simple like CREATE statements in that they do just what you think. The syntax tells SQL which columns in the specified tables you would like to update with what data. For instance, [ UPDATE NewTable SET column1 = value1 ].<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><b>DELETE <\/b><span style=\"font-weight: 400;\">is also explanatory. You can DELETE all the data in a table simply by specifying which table you would like to clear, for example, [ DELETE NewTable ]. This doesn\u2019t delete the table, but only the data contained in the table. If you wish to delete the actual table, you will need to use a DROP statement, which is [ DROP TABLE NewTable ]. By having two different commands, you can make sure you\u2019re performing the desired action.<\/span><\/li>\n<\/ul>\n<h2><b>User Operations<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You would use a CREATE statement to create a new user much the same way you would with any other object, which would be [ CREATE USER User1 ] and then the user id of the user you wish to create. To grant permissions to that user, you would use the GRANT statement followed by the user name and the permissions you would like to grant that user. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, to allow the user to read data from the database, you would use the [ GRANT SELECT TO User1 ] statement. You can also add multiple permissions by separating them with commas, for example, [ GRANT SELECT, UPDATE, DELETE, INSERT, EXECUTE TO User 1 ].<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Learning basic T-SQL commands is fairly easy. However, if you really want to dive into Transact-SQL and learn how to make it work for you, why not consider some in-depth training. This tutorial only barely scratches the surface. With training provided by a <\/span><a href=\"https:\/\/www.onlc.com\/contact-onlc.htm\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">top-notch training service such as ONLC<\/span><\/a><span style=\"font-weight: 400;\">, you can open up the world of database programming. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">With the ability to attend training at one of their over 300 Remote Learning Classrooms or online in your home or office, you can easily obtain that vital training you\u2019ll need to become proficient in one of the most powerful information technologies available today. Why not give us a call and find out how to get trained today?<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>T-SQL or Transact Structured Query Language is a programming language for databases. Most of the major database systems such as Oracle, Microsoft SQL Server and MySQL, utilize some form of T-SQL. It\u2019s essentially a language that lets you quickly and easily do almost anything that you would ever want to do with a database. Let\u2019s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":339,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-certifications"],"aioseo_notices":[],"modified_by":"blogadmin","_links":{"self":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":2,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":1275,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions\/1275"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlc.com\/blog\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}