{"id":81,"date":"2026-02-11T08:50:42","date_gmt":"2026-02-11T06:50:42","guid":{"rendered":"https:\/\/timofeistoljarov.wordpress.com\/?page_id=81"},"modified":"2026-02-11T08:50:42","modified_gmt":"2026-02-11T06:50:42","slug":"veebipood-sql-lausete-koostamine","status":"publish","type":"page","link":"https:\/\/timofeistoljarov.eu\/wp\/andmebaasid\/veebipood-sql-lausete-koostamine\/","title":{"rendered":"Veebipood SQL lausete koostamine"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">andmebaasi diagramm SQL Serverist<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/timofeistoljarov.eu\/wp\/wp-content\/uploads\/2026\/02\/image-9-1.png?w=1024\" alt=\"\" class=\"wp-image-84\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">CREATE DATABASE veebipoodStoljarov;<br>USE veebipoodStoljarov;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Production<br>&#8212; table Categories<br>CREATE TABLE categories(<br>category_id int PRIMARY KEY identity(1,1),<br>category_name varchar(30) UNIQUE<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INSERT INTO categories(category_name)<br>VALUES (&#8216;T-s\u00e4rgid&#8217;), (&#8216;Tossud&#8217;), (&#8216;Kingad&#8217;), (&#8216;Mantel&#8217;), (&#8216;Pusad&#8217;);<br>SELECT * FROM categories;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;table brands<br>CREATE TABLE brands(<br>brand_id int PRIMARY KEY identity(1,1),<br>brand_name varchar(30) UNIQUE<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INSERT INTO brands(brand_name)<br>VALUES (&#8216;Adidas&#8217;), (&#8216;Nike&#8217;), (&#8216;Calvin Klein&#8217;), (&#8216;Gucci&#8217;), (&#8216;Hugo boss&#8217;);<br>SELECT * FROM brands;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;table products<br>CREATE TABLE products(<br>product_id int PRIMARY KEY identity(1,1),<br>product_name varchar(50),<br>brand_id int,<br>FOREIGN KEY (brand_id) references brands(brand_id),<br>category_id int,<br>FOREIGN KEY (category_id) references categories(category_id),<br>model_year int CHECK(model_year&lt;2027),<br>list_price decimal(7,2)<br>);<br>INSERT INTO products(product_name, brand_id, category_id, model_year, list_price)<br>VALUES (&#8216;Adidas tossud&#8217;, 1, 2, 2019, 60),<br>(&#8216;Nike t-s\u00e4rk&#8217;, 2, 1, 2025, 45.59),<br>(&#8216;Calvin Klein pusa&#8217;, 3, 5, 2018, 100.99),<br>(&#8216;Gucci Mantel&#8217;, 4, 4, 2020, 159.99),<br>(&#8216;Hugo boss Kingad&#8217;, 5, 3, 2026, 25.99);<br>SELECT * FROM products;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;Sales<br>&#8211;table customers<br>CREATE TABLE customers(<br>customer_id int PRIMARY KEY identity(1,1),<br>first_name varchar(20),<br>last_name varchar(30),<br>phone int,<br>email TEXT,<br>street TEXT,<br>city TEXT,<br>state_ TEXT,<br>zip_code char(5)<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INSERT INTO customers(first_name, last_name, phone, email, street, city, state_, zip_code)<br>VALUES (&#8216;Konstantin&#8217;, &#8216;Guakamole&#8217;, &#8216;52123456&#8217;, &#8216;kguakomol@mail.ee&#8217;, &#8216;\u00dcmera 8&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, &#8216;11093&#8217;),<br>(&#8216;Dmitro&#8217;, &#8216;Gusenko&#8217;, &#8216;5312345&#8217;, &#8216;DGusen@mail.ee&#8217;, &#8216;Seli 2&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, &#8216;13112&#8217;),<br>(&#8216;Danil&#8217;, &#8216;Kolbasenko&#8217;, &#8216;5412345&#8217;, &#8216;DanilKolbas@mail.ee&#8217;, &#8216;Kivila 2&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, &#8216;12121&#8217;);<br>SELECT * FROM customers;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; stores table<br>CREATE TABLE stores(<br>store_id int PRIMARY KEY identity(1,1),<br>store_name varchar(20),<br>phone int,<br>email TEXT,<br>street TEXT ,<br>city TEXT,<br>state_ TEXT,<br>zip_code char(5)<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INSERT INTO stores(store_name, phone, email, street, city, state_, zip_code)<br>VALUES (&#8216;Indian Shop&#8217;, 52123456, &#8217;indianstore@mail.ee&#8217;, &#8216;\u00dcmera 15&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, 11090),<br>(&#8216;Mania Clothes&#8217;, 5312345, &#8216;ManiaClothes@mail.ee&#8217;, &#8216;Seli 2&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, 13112),<br>(&#8216;Clothes And More&#8217;, 5412211, &#8216;candm@mail.ee&#8217;, &#8216;Kivila 2&#8217;, &#8216;Tallinn&#8217;, &#8216;Harjumaa&#8217;, 12123);<br>SELECT * FROM stores;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;staff table<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CREATE TABLE staffs(<br>staff_id int PRIMARY KEY identity(1,1),<br>first_name varchar(20),<br>last_name varchar(30),<br>email TEXT,<br>phone int,<br>active TEXT,<br>store_id int,<br>FOREIGN KEY (store_id) references stores(store_id),<br>manager_id int,<br>FOREIGN KEY (manager_id) references staffs(staff_id)<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INSERT INTO staffs(first_name, last_name, email, phone, active, store_id, manager_id)<br>VALUES (&#8216;Maksimilian&#8217;,&#8217;Puhtejev&#8217;, &#8216;manag.maks@indianshop.ee&#8217;, 52123456, &#8216;true&#8217;, 1, 1),<br>(&#8216;Sergei&#8217;,&#8217;Puhtejev&#8217;, &#8216;SergeiP@indianshop.ee&#8217;, 54123567, &#8216;true&#8217;, 1, 1),<br>(&#8216;Andrey&#8217;,&#8217;Visel&#8217;, &#8216;AndreyV@indianshop.ee&#8217;, 52123456, &#8216;false&#8217;, 2, 3);<br>SELECT * FROM staffs;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;Table Orders<br>CREATE TABLE orders(<br>order_id int PRIMARY KEY identity(1,1),<br>customer_id int,<br>FOREIGN KEY (customer_id) references customers(customer_id),<br>order_status varchar(30) check(order_status=&#8217;valmis&#8217; or order_status=&#8217;t\u00f6\u00f6tlemisel&#8217; or order_status=&#8217;makstud&#8217;),<br>order_date DATE,<br>required_date DATE,<br>shipped_date DATE,<br>store_id int,<br>FOREIGN KEY (store_id) references stores(store_id),<br>staff_id int<br>FOREIGN KEY (staff_id) references staffs(staff_id),<br>);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT * FROM orders;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;stocks table<br>CREATE TABLE stocks(<br>store_id int,<br>FOREIGN KEY (store_id) references stores(store_id),<br>product_id int<br>FOREIGN KEY (product_id) references products(product_id),<br>quantity int<br>)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8212; Order_items Table<br>CREATE TABLE order_items(<br>order_id int,<br>FOREIGN KEY (order_id) references orders(order_id),<br>item_id int PRIMARY KEY identity(1,1),<br>product_id int,<br>);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>andmebaasi diagramm SQL Serverist CREATE DATABASE veebipoodStoljarov;USE veebipoodStoljarov; &#8212; Production&#8212; table CategoriesCREATE TABLE categories(category_id int PRIMARY KEY identity(1,1),category_name varchar(30) UNIQUE); INSERT INTO categories(category_name)VALUES (&#8216;T-s\u00e4rgid&#8217;), (&#8216;Tossud&#8217;), (&#8216;Kingad&#8217;), (&#8216;Mantel&#8217;), (&#8216;Pusad&#8217;);SELECT * FROM categories; &#8211;table brandsCREATE TABLE brands(brand_id int PRIMARY KEY identity(1,1),brand_name varchar(30) UNIQUE); INSERT INTO brands(brand_name)VALUES (&#8216;Adidas&#8217;), (&#8216;Nike&#8217;), (&#8216;Calvin Klein&#8217;), (&#8216;Gucci&#8217;), (&#8216;Hugo boss&#8217;);SELECT * FROM brands; &#8211;table [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":7,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-81","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/pages\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":0,"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/pages\/81\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/pages\/7"}],"wp:attachment":[{"href":"https:\/\/timofeistoljarov.eu\/wp\/wp-json\/wp\/v2\/media?parent=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}