Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

SQLQuery8

Uploaded by

Adrian Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQLQuery8

Uploaded by

Adrian Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE SCHEMA production;

go

CREATE TABLE production.categories (


category_id INT IDENTITY (1, 1) PRIMARY KEY,
category_name VARCHAR (255) NOT NULL
);

insert into production.categories values ('sayur');

CREATE TABLE production.brands (


brand_id INT IDENTITY (1, 1) PRIMARY KEY,
brand_name VARCHAR (255) NOT NULL
);

CREATE TABLE production.products (


product_id VARCHAR(20) PRIMARY KEY,
product_name VARCHAR (255) NOT NULL,
brand_id INT NOT NULL,
category_id INT NOT NULL,
model_year SMALLINT NOT NULL,
list_price DECIMAL (10, 2) NOT NULL,
FOREIGN KEY (category_id) REFERENCES production.categories (
category_id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (brand_id) REFERENCES production.brands (brand_id) ON DELETE
CASCADE ON UPDATE CASCADE
);

insert into production.products values ('K0001','Bedak Muka',1,1,2023,50000);


SELECT * From production.brands;

insert into production.brands values ('My Bella')

insert into production.products values ('K0003','Bedak Muka',1,3,2023,75000);

select a.product_name 'Nama Produk', a.list_price as 'Harga Produk' From


buma_base.production.products a

alter table buma_base.production.categories add categories_color VARCHAR(60) null;

alter table buma_base.production.categories drop column categories_color;

alter table buma_base.production.categories add categories_color VARCHAR(60) null;

alter table buma_base.production.categories alter column categories_color char(30)


null;

update buma_base.production.categories set categories_color='Hitam' where


category_id=3

update buma_base.production.products set model_year='2021', list_price='45000'


where category_id=1

delete from buma_base.production.categories where category_id=3;

USE buma_base;

Insert into buma_base.production.products values ('K0003','Sabun


Muka',1,2,2023,80000);
--berupa komentar dan tidak dieksekusi, hanya 1 baris
/* komentar
multi
baris */

update buma_base.production.products set product_name='Shampoo', list_price='45000'


where category_id=1

insert into buma_base.production.products values ('K0004','Sikat


Gigi',1,2,2023,66000);

select product_name, model_year from production.products;

select product_name, model_year from production.products where model_year=2023;

insert into production.categories values ('makanan','hitam');

insert into buma_base.production.products values ('K0005','Bakso',1,4,2020,35000);

insert into buma_base.production.products values ('K0006','Nasi


Goreng',1,4,2020,20000);

select product_name, model_year, list_price from production.products;

select product_name, model_year, list_price from production.products where


list_price>20000;

select product_name, model_year, list_price from production.products where


list_price>=20000;

select product_name, model_year, list_price from production.products where


list_price>20000 and list_price<=50000

select product_name, model_year, list_price from production.products where


list_price>35000 or list_price=50000

select product_name, model_year, list_price from production.products where


product_name like '%ka';

select product_name, model_year, list_price from production.products where


product_name='muka';

select product_name, model_year, list_price from production.products where


model_year like '___3';

select
product_name,
model_year,
category_id,
list_price,
list_price*category_id as perkalian,
list_price*cast(category_id as int) as perkalian_1,
list_price*convert(int,category_id) as perkalian_2,
list_price/cast(category_id as int) as perkalian_3
from production.products;

You might also like