{"id":83,"date":"2018-04-01T22:43:11","date_gmt":"2018-04-01T15:43:11","guid":{"rendered":"http:\/\/www.sqlservertutorial.net\/?page_id=83"},"modified":"2021-07-26T07:45:57","modified_gmt":"2021-07-26T00:45:57","slug":"sql-server-sample-database","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/getting-started\/sql-server-sample-database\/","title":{"rendered":"SQL Server Sample Database"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the SQL Server sample database called BikeStores.<\/p>\n\n\n\n<p>The following illustrates the BikeStores database diagram:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"602\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png\" alt=\"\" class=\"wp-image-96\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png 742w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database-300x243.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/figure>\n\n\n\n<p>As you can see from the diagram, the BikeStores sample database has two schemas sales and production, and these schemas have nine tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='database-tables'>Database Tables <a href=\"#database-tables\" class=\"anchor\" id=\"database-tables\" title=\"Anchor for Database Tables\">#<\/a><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id='table-sales-stores'>Table sales.stores <a href=\"#table-sales-stores\" class=\"anchor\" id=\"table-sales-stores\" title=\"Anchor for Table sales.stores\">#<\/a><\/h3>\n\n\n\n<p>The&nbsp; <code>sales.stores<\/code> table includes the store&#8217;s information. Each store has a store name, contact information such as phone and email, and an address including street, city, state, and zip code.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.stores (\n\tstore_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tstore_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tphone <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">25<\/span>),\n\temail <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>),\n\tstreet <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>),\n\tcity <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>),\n\tstate <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">10<\/span>),\n\tzip_code <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">5<\/span>)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-sales-staffs'>Table sales.staffs <a href=\"#table-sales-staffs\" class=\"anchor\" id=\"table-sales-staffs\" title=\"Anchor for Table sales.staffs\">#<\/a><\/h3>\n\n\n\n<p>The &nbsp;<code>sales.staffs<\/code> table stores the essential information of staffs including first name, last name. It also contains the communication information such as email and phone.<\/p>\n\n\n\n<p>A staff works at a store specified by the value in the <code>store_id<\/code> column. A store can have one or more staffs.<\/p>\n\n\n\n<p>A staff reports to a&nbsp;store manager specified by the value in the&nbsp;<code>manager_id<\/code> column. If the value in the manager_id is null, then the staff is the top manager.<\/p>\n\n\n\n<p>If a staff no longer works for any stores, the value in the active column is set to zero.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.staffs (\n\tstaff_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">50<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\temail <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">UNIQUE<\/span>,\n\tphone <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">25<\/span>),\n\tactive <span class=\"hljs-built_in\">tinyint<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tstore_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tmanager_id <span class=\"hljs-built_in\">INT<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (store_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.stores (store_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (manager_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.staffs (staff_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-production-categories'>Table production.categories <a href=\"#table-production-categories\" class=\"anchor\" id=\"table-production-categories\" title=\"Anchor for Table production.categories\">#<\/a><\/h3>\n\n\n\n<p>The <code>production.categories<\/code> table stores the bike&#8217;s categories such as children bicycles, comfort bicycles,&nbsp;and electric bikes.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> production.categories (\n\tcategory_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tcategory_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-production-brands'>Table production.brands <a href=\"#table-production-brands\" class=\"anchor\" id=\"table-production-brands\" title=\"Anchor for Table production.brands\">#<\/a><\/h3>\n\n\n\n<p>The &nbsp;<code>production.brands<\/code>&nbsp;table stores the brand&#8217;s information of bikes, for example,&nbsp;Electra, Haro, and Heller.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> production.brands (\n\tbrand_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tbrand_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-production-products'>Table production.products <a href=\"#table-production-products\" class=\"anchor\" id=\"table-production-products\" title=\"Anchor for Table production.products\">#<\/a><\/h3>\n\n\n\n<p>The <code>production.products<\/code> table stores the product&#8217;s information such as name, brand, category, model year, and list price.<\/p>\n\n\n\n<p>Each product belongs to a brand specified by the <code>brand_id<\/code> column. Hence, a brand may have zero or many products.<\/p>\n\n\n\n<p>Each product also belongs a category specified by the <code>category_id<\/code> column. Also, each category may have zero or many products.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> production.products (\n\tproduct_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tproduct_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tbrand_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tcategory_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tmodel_year <span class=\"hljs-built_in\">SMALLINT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlist_price <span class=\"hljs-built_in\">DECIMAL<\/span> (<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (category_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> production.categories (category_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (brand_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> production.brands (brand_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-sales-customers'>Table sales.customers <a href=\"#table-sales-customers\" class=\"anchor\" id=\"table-sales-customers\" title=\"Anchor for Table sales.customers\">#<\/a><\/h3>\n\n\n\n<p>The &nbsp;<code>sales.customers<\/code> table stores customer&#8217;s information including first name, last name, phone, email, street, city, state and zip code.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.customers (\n\tcustomer_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tfirst_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlast_name <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tphone <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">25<\/span>),\n\temail <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tstreet <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">255<\/span>),\n\tcity <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">50<\/span>),\n\tstate <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">25<\/span>),\n\tzip_code <span class=\"hljs-built_in\">VARCHAR<\/span> (<span class=\"hljs-number\">5<\/span>)\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-sales-orders'>Table sales.orders <a href=\"#table-sales-orders\" class=\"anchor\" id=\"table-sales-orders\" title=\"Anchor for Table sales.orders\">#<\/a><\/h3>\n\n\n\n<p>The <code>sales.orders<\/code> table stores the sales order&#8217;s header information including customer, order status, order date, required date, shipped date.<\/p>\n\n\n\n<p>It also stores the information on where the sales transaction was created (store) and who created it (staff).<\/p>\n\n\n\n<p>Each sales order has a&nbsp;row in the sales_orders table. A sales order has one or many line items stored in the <code>sales.order_items<\/code> table.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.orders (\n\torder_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> (<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>) PRIMARY <span class=\"hljs-keyword\">KEY<\/span>,\n\tcustomer_id <span class=\"hljs-built_in\">INT<\/span>,\n\torder_status <span class=\"hljs-built_in\">tinyint<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\t<span class=\"hljs-comment\">-- Order status: 1 = Pending; 2 = Processing; 3 = Rejected; 4 = Completed<\/span>\n\torder_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\trequired_date <span class=\"hljs-built_in\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tshipped_date <span class=\"hljs-built_in\">DATE<\/span>,\n\tstore_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tstaff_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (customer_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.customers (customer_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (store_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.stores (store_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (staff_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.staffs (staff_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">NO<\/span> <span class=\"hljs-keyword\">ACTION<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='tablesales-order_items'>Table&nbsp;sales.order_items <a href=\"#tablesales-order_items\" class=\"anchor\" id=\"tablesales-order_items\" title=\"Anchor for Table&nbsp;sales.order_items\">#<\/a><\/h3>\n\n\n\n<p>The <code>sales.order_items<\/code> table stores the line items of a sales order. Each line item belongs to a sales order specified by the <code>order_id<\/code> column.<\/p>\n\n\n\n<p>A sales order line item includes product, order quantity, list price, and discount.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> sales.order_items(\n\torder_id <span class=\"hljs-built_in\">INT<\/span>,\n\titem_id <span class=\"hljs-built_in\">INT<\/span>,\n\tproduct_id <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tquantity <span class=\"hljs-built_in\">INT<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tlist_price <span class=\"hljs-built_in\">DECIMAL<\/span> (<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span>,\n\tdiscount <span class=\"hljs-built_in\">DECIMAL<\/span> (<span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span> (order_id, item_id),\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (order_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.orders (order_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (product_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> production.products (product_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='table-production-stocks'>Table production.stocks <a href=\"#table-production-stocks\" class=\"anchor\" id=\"table-production-stocks\" title=\"Anchor for Table production.stocks\">#<\/a><\/h3>\n\n\n\n<p>The <code>production.stocks<\/code> table stores the inventory information i.e. the quantity of a particular product in a specific store.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> production.stocks (\n\tstore_id <span class=\"hljs-built_in\">INT<\/span>,\n\tproduct_id <span class=\"hljs-built_in\">INT<\/span>,\n\tquantity <span class=\"hljs-built_in\">INT<\/span>,\n\tPRIMARY <span class=\"hljs-keyword\">KEY<\/span> (store_id, product_id),\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (store_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> sales.stores (store_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>,\n\t<span class=\"hljs-keyword\">FOREIGN<\/span> <span class=\"hljs-keyword\">KEY<\/span> (product_id) \n        <span class=\"hljs-keyword\">REFERENCES<\/span> production.products (product_id) \n        <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">DELETE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span> <span class=\"hljs-keyword\">ON<\/span> <span class=\"hljs-keyword\">UPDATE<\/span> <span class=\"hljs-keyword\">CASCADE<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Click the following link to download the sample database script:<\/p>\n\n\n\n<p><a class=\"buttonDownload\" href=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.zip\">Download SQL Server Sample Database<\/a><\/p>\n\n\n\n<p>Now, you should be familiar with the BikeStores sample database and ready to load it into the SQL Server.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"83\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/getting-started\/sql-server-sample-database\/\"\n\t\t\t\tdata-post-title=\"SQL Server Sample Database\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"83\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/getting-started\/sql-server-sample-database\/\"\n\t\t\t\tdata-post-title=\"SQL Server Sample Database\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you&#8217;ll learn about the SQL Server sample database called BikeStores. The following illustrates the BikeStores database diagram: As you can see from the diagram, the BikeStores sample database has two schemas sales and production, and these schemas have nine tables. Database Tables # Table sales.stores # The&nbsp; sales.stores table includes the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":394,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-83","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Server Sample Database<\/title>\n<meta name=\"description\" content=\"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Sample Database\" \/>\n<meta property=\"og:description\" content=\"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-26T00:45:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/\",\"name\":\"SQL Server Sample Database\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-Sample-Database.png\",\"datePublished\":\"2018-04-01T15:43:11+00:00\",\"dateModified\":\"2021-07-26T00:45:57+00:00\",\"description\":\"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-Sample-Database.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/SQL-Server-Sample-Database.png\",\"width\":742,\"height\":602},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/sql-server-sample-database\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Started with SQL Server\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/getting-started\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Server Sample Database\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server Sample Database","description":"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.","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:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Sample Database","og_description":"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.","og_url":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2021-07-26T00:45:57+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/","url":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/","name":"SQL Server Sample Database","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png","datePublished":"2018-04-01T15:43:11+00:00","dateModified":"2021-07-26T00:45:57+00:00","description":"This tutorial provides you with a SQL Server Sample Database called BikeStores, which allows you to start practicing with SQL Server quickly and effectively.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/SQL-Server-Sample-Database.png","width":742,"height":602},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/sql-server-sample-database\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"Getting Started with SQL Server","item":"https:\/\/www.sqlservertutorial.net\/getting-started\/"},{"@type":"ListItem","position":3,"name":"SQL Server Sample Database"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":1,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/83\/revisions"}],"predecessor-version":[{"id":2821,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/83\/revisions\/2821"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/394"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}