{"id":20862,"date":"2020-08-06T00:00:35","date_gmt":"2020-08-06T07:00:35","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20862"},"modified":"2021-04-27T00:20:27","modified_gmt":"2021-04-27T07:20:27","slug":"sql-contains","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/sql-contains\/","title":{"rendered":"How to Use the SQL Contains Command"},"content":{"rendered":"\n<p>There are many SQL statements and functions to query your database and retrieve or figure out useful information. One such function is the <code>CONTAINS()<\/code> function. This particular statement is not a standard SQL function \u2013 depending on which database you use, the <code>CONTAINS()<\/code> function operates differently. In this article, we talk about the <code>CONTAINS()<\/code> function as it relates to SQL Server and touch upon how it differs when you use another database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-basic-usage-and-syntax\">Basic Usage and Syntax<\/h2>\n\n\n\n<p>At its core, the <code>CONTAINS()<\/code> function takes one substring and does a search to see if it\u2019s in another string. For Microsoft SQL Server, <code>CONTAINS()<\/code> allows for a full text pattern match SQL search queries on your table. It returns a boolean value that indicates whether the function is truthy or falsy.&nbsp;<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT &lt;columnName&gt; FROM &lt;yourTable&gt; WHERE CONTAINS (&lt;columnName&gt;, '&lt;yourSubstring&gt;');<\/pre><\/div>\n\n\n\n<p>All of the places in between a set of &lt;&gt; is your customized naming. Notice your substring is in between a set of quotes. The column names are the variable names you set your column names to when you created your table.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>CREATE TABLE MyTable\n    ([name] varchar(26), [occupation] varchar(57))\n;\n\nINSERT INTO MyTable\n    ([name], [occupation])\nVALUES\n    ('User 1', 'Web Developer'),\n    ('User 2', 'Musician'),\n    ('User 3', 'Doctor')\n;\n\nSELECT name, occupation FROM myTable WHERE CONTAINS (name, 'User');<\/pre><\/div>\n\n\n\n<p>If you have your table set up to be full-text indexed, then you can run the query above. The search looks for the pattern of the substring in its entirety \u2013 it does not look for misspellings or synonyms.<br><\/p>\n\n\n\n<p>If you are unsure of how to set up your database to be full-text indexed, check the SQL LIKE clause. It\u2019s similar to CONTAINS, but easier to set up out of the box.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT\n  name,\n  occupation\nFROM\n  MyTable\nWHERE name LIKE 'User%';<\/pre><\/div>\n\n\n\n<p>The % after the string \u2018User\u2019 indicates anything after \u2018User\u2019. So this code will return:<br><\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>name<\/strong><\/td><td><strong>occupation<\/strong><\/td><\/tr><tr><td>User 1<\/td><td>Web Developer<\/td><\/tr><tr><td>User 2<\/td><td>Musician<\/td><\/tr><tr><td>User 3<\/td><td>Doctor<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Other databases use the CONTAINS function in different ways \u2013 it doesn\u2019t necessarily mean the same in SQL Server, for instance, that it means in PostgreSQL.&nbsp;<br><\/p>\n\n\n\n<p>For more information please check out your respective database\u2019s documentation. For more information about the LIKE clause, please take a look at this blog post James Gallagher wrote about it on <a href=\"https:\/\/www.careerkarma.com\/blog\/sql-like\/\">Career Karma<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"There are many SQL statements and functions to query your database and retrieve or figure out useful information. One such function is the CONTAINS() function. This particular statement is not a standard SQL function \u2013 depending on which database you use, the CONTAINS() function operates differently. In this article, we talk about the CONTAINS() function&hellip;","protected":false},"author":77,"featured_media":9207,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17284],"tags":[],"class_list":{"0":"post-20862","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-sql"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"SQL","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use the SQL Contains Command %<\/title>\n<meta name=\"description\" content=\"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let&#039;s take a look at this method on Career Karma\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/sql-contains\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use the SQL Contains Command\" \/>\n<meta property=\"og:description\" content=\"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let&#039;s take a look at this method on Career Karma\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/sql-contains\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-06T07:00:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-27T07:20:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"How to Use the SQL Contains Command\",\"datePublished\":\"2020-08-06T07:00:35+00:00\",\"dateModified\":\"2021-04-27T07:20:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/\"},\"wordCount\":331,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg\",\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/\",\"name\":\"How to Use the SQL Contains Command %\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg\",\"datePublished\":\"2020-08-06T07:00:35+00:00\",\"dateModified\":\"2021-04-27T07:20:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let's take a look at this method on Career Karma\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg\",\"width\":1000,\"height\":667,\"caption\":\"desktop screen in a darkened room with ambient light\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql-contains\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Use the SQL Contains Command\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\\\/\\\/www.linkedin.com\\\/in\\\/cmvnk\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/christina-kopecky\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use the SQL Contains Command %","description":"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let's take a look at this method on Career Karma","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/sql-contains\/","og_locale":"en_US","og_type":"article","og_title":"How to Use the SQL Contains Command","og_description":"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let's take a look at this method on Career Karma","og_url":"https:\/\/careerkarma.com\/blog\/sql-contains\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-06T07:00:35+00:00","article_modified_time":"2021-04-27T07:20:27+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"How to Use the SQL Contains Command","datePublished":"2020-08-06T07:00:35+00:00","dateModified":"2021-04-27T07:20:27+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/"},"wordCount":331,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg","articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/sql-contains\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/","url":"https:\/\/careerkarma.com\/blog\/sql-contains\/","name":"How to Use the SQL Contains Command %","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg","datePublished":"2020-08-06T07:00:35+00:00","dateModified":"2021-04-27T07:20:27+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"The SQL Contains method is used in MS SQL Server to find entries that have a specified substring. Let's take a look at this method on Career Karma","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/sql-contains\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2019\/12\/blake-connally-IKUYGCFmfw4-unsplash-1.jpg","width":1000,"height":667,"caption":"desktop screen in a darkened room with ambient light"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/sql-contains\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL","item":"https:\/\/careerkarma.com\/blog\/sql\/"},{"@type":"ListItem","position":3,"name":"How to Use the SQL Contains Command"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=20862"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20862\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/9207"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}