CodeSolved

A comprehensive source of programming questions and exercises

Mobile Store Database

Practice Easy 254/ Download 413 Views

Design a database for a mobile store that includes two Customers and Orders (orders) tables.

The customer's table should include:

Full name
Mobile number
Address
Year of birth
ID


And the order table should include:

Must be specified. Any order is for which user
Mobile Model purchased
Mobile brand purchased
Price

3 Answers

create database Mobileـstore
create table customers
(
cus_id int constraint PK__customer_cus_id primary key,
cus_fullname nvarchar(60),
cus_phone char(11),
cus_address nvarchar(max),
cus_brithday date
)
create table orders
(
cus_id int constraint FK__customer_cus_id foreign key references customers(cus_id),
mobile_model nvarchar(50),
mobile_brand nvarchar(30),
mobile_price money
)
import sqlite3

db = sqlite3.connect("shop_db.sqlite")
cur = db.cursor()

cur.execute('''
            CREATE TABLE IF NOT EXISTS customers(
            id INTEGER PRIMARY KEY,
            f_name VARCHAR(50),
            phone VARCHAR(11),
            address STRING,
            birth_year INTEGER
            )
        ''')

db.commit()

cur.execute('''
            CREATE TABLE IF NOT EXISTS orders(
            id INTEGER PRIMARY KEY,
            model STRING,
            brand STRING,
            price INTEGER,
            user_id INTEGER
            )
        ''')

db.commit()
db.close()
User 362 Download DataBase
-- ایجاد جدول مشتریان
CREATE TABLE customers (
    customer_id INT AUTO_INCREMENT PRIMARY KEY,
    full_name VARCHAR(100) NOT NULL,
    mobile_number VARCHAR(15) NOT NULL UNIQUE,
    address VARCHAR(255) NOT NULL,
    birth_year INT NOT NULL
);

-- ایجاد جدول سفارشات
CREATE TABLE orders (
    order_id INT AUTO_INCREMENT PRIMARY KEY,
    customer_id INT NOT NULL,
    mobile_model VARCHAR(100) NOT NULL,
    mobile_brand VARCHAR(100) NOT NULL,
    price DECIMAL(10, 2) NOT NULL,
    FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
Mma123 Download DataBase

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close