You are on page 1of 3

-- Structured Query Language (this the language we use in MySQL for Data Management)

-- Create Database
-- select database --- here is a news, new learners tend to forget this step. trust me even after
telling
-- this i ll experience same errors : ha ha ha haaaaaa
-- create table
-- display table
-- insert record in Table.

-- What is a Database ?
-- a Database is a container like structure used to store or organise TABLES.

create database dsc56_bootcamp;

-- points to remember
-- SQL is Case IN-Sensitive Language
-- Each SQL Statement must terminate using ;(semicolon)
-- press command+return(mac) , ctrl+enter (windows) to execute sql statement.

-- select database
use dsc56_bootcamp;

-- let us create a table to keep track of Product Inventory

create table Stock(


productid int primary key,
pname varchar(255),
pprice float,
pdesc varchar(600)
);

-- how to display data ? answer: using select statement


-- syntax: select * from <tableName>

select * from stock;

select pname,pprice from stock;

-- let us learn how to insert record a record in a table using insert statement
-- syntax: insert <tableName> values ( ? , ? , ? , ?);
insert stock values (101, 'acer laptop',50000,' an entertainment laptop');

select * from stock;

insert stock values (102, 'HP laptop',120000,' an Office laptop');


insert stock values (103, 'DELL laptop',370000,' an Gaming laptop');

select * from stock;


insert stock values (103, 'DELL laptop',370000,' an Gaming laptop');

-- Creating Foreign Keys


-- let us create a table to keep track of SALES
create table Stock(
productid int primary key,
pname varchar(255),
pprice float,
pdesc varchar(600)
);

create table sales(


productid int,
qty int ,
remarks varchar(500) ,
foreign key (productid) references stock(productid)
);

select *From stock;

insert sales values(105, 10,'fraud ORDER');

select * from sales;

You might also like