{"id":9050,"date":"2022-07-25T06:47:00","date_gmt":"2022-07-25T04:47:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=9050"},"modified":"2022-07-28T13:21:47","modified_gmt":"2022-07-28T11:21:47","slug":"list-user-defined-table-types-sql-server","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/list-user-defined-table-types-sql-server\/","title":{"rendered":"List user defined table types in SQL Server (UDT)"},"content":{"rendered":"\n<p>How to list user defined table types in a SQL Server database? First of all, users declare User Defined Table Type as a particular table structure in the database. This UDT is reusable in database, it is not a system table. It&#8217;s a good practice to ensure users can&#8217;t insert data with different types or length for example. Or even from different data structure. <\/p>\n\n\n\n<p>For example, it is very possible that a user insert numbers in a texts filed. So the controls on the input screen and all over the process are key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-t-sql-script-to-list-user-defined-table-types-in-a-sql-server-database-udt\">T-SQL script to list user defined table types in a SQL Server database (UDT)<\/h2>\n\n\n\n<p>For example, we use User Defined Tables (the abbreviation is UDT) objects to call stored procedures. But also functions and they help to control the input parameters conditions.<\/p>\n\n\n\n<p>It means that instead of passing one or more parameters as variables, we pass a UDT to the procedure or function. The goal is to validate the input data structure.<\/p>\n\n\n\n<p>To list User Defined Tables simply execute this T-SQL query to retrieve data from the table_types system table :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT\n\tname, \n\tsystem_type_id, \n\tuser_type_id, \n\tschema_id, \n\tprincipal_id, \n\tmax_length, \n\tprecision, \n\tscale, \n\tcollation_name, \n\tis_nullable, \n\tis_user_defined, \n\tis_assembly_type, \n\tdefault_object_id, \n\trule_object_id, \n\tis_table_type\nFROM \tSYS.TABLE_TYPES\nWHERE \tIS_USER_DEFINED = 1;\n<\/pre>\n\n\n\n<p>The result is the list of all the user <a href=\"https:\/\/www.dictionary.com\/browse\/defined\" target=\"_blank\" rel=\"noreferrer noopener\">defined<\/a> table types available in the SQL Server database. Along with their names and other metadata.<\/p>\n\n\n\n<p>To sum-up, this short MS SQL tutorial do not explain how to create a user defined table. But simply how to list them. It is useful to perform checks and impact analysis on a SQL development project.<\/p>\n\n\n\n<p>Check out <strong><a href=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/\">how to create a table with a T-SQL<\/a><\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-tutoriels-et-exemples-sql-server-et-microsoft-it wp-block-embed-tutoriels-et-exemples-sql-server-et-microsoft-it\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"ZPq1DYiafs\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/\">CREATE TABLE with SQL Server<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;CREATE TABLE with SQL Server&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/create-table-sql-server\/embed\/#?secret=HLUUTYrgpL#?secret=ZPq1DYiafs\" data-secret=\"ZPq1DYiafs\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to list user defined table types in a SQL Server database? First of all, users declare User Defined Table Type as a particular table structure in the database. This UDT is reusable in database, it is not a <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/list-user-defined-table-types-sql-server\/\" title=\"List user defined table types in SQL Server (UDT)\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5514,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-9050","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=9050"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9050\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5514"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=9050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=9050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=9050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}