Commits (3)
use app;
create table app.orders (
order_id integer comment 'Primary Key. Meaningless value to the business.',
order_number varchar(20) not null comment 'Order Number. Public ID for this order. Can share with other systems.',
amount_paid integer not null comment 'Amount paid by buyer in USD cents.',
product_category varchar(20) not null comment 'Product Category to which this purchase belongs.',
constraint pk_orders primary key (order_id),
constraint uq_orders_order_number unique (order_number)
comment 'Purchases made by buyers.'
insert into app.orders(
concat('P', lpad(o.order_id, 9, '0')) as order_number,
(rand() * 100 + 1) * 100 as amount_paid, -- cents, not dollars
(select category from (select 'coffee' union all select 'donuts' union all select 'bagels') c(category) order by rand() limit 1) as category
from (
-- generate N rows so we can create fake data.
select row_number() over() as order_id
from information_schema.columns c1
cross join information_schema.columns c2
limit 50000
) o;
create index ix_orders_product_category on app.orders(product_category);
create index ix_orders_order_number on app.orders(order_number);