How To Install MySQL + Workbench on Windows
How To Install MySQL + Workbench on Mac
How To Install MySQL + Workbench on Ubuntu Linux
https://www.youtube.com/watch?v=ohln8gMWxYg
/*
Stud_Id Stud_name   Gender  Course_Name Course_No.
1   Zain    Male    OOP 123
2   Mike    Male    DB  321
*/
-- SQL syntax to create table
-- CREATE TABLE table_name (column_name column_type(LENGHT OF DATA TYPE))
CREATE TABLE student (
stud_id INT, 
stud_name VARCHAR(256),
gender VARCHAR(256),
course_name VARCHAR(256),
course_no INT);
select * from student;
select 
stud_id,
stud_name,
gender,
course_name,
course_no
from student;
select 
stud_id,
stud_name,
course_name
from student;
-- SQL syntax of INSERTING data into Table
/*
INSERT INTO table_name (filed1, filed2 .......filedN)
VALUES
(vlaue1,value2 .......valueN)
*/
INSERT INTO student (stud_id,stud_name,gender,course_name,course_no)
VALUES
(1,"Zain","Male","OOP",123);
select * from student;
INSERT INTO student (stud_id,stud_name,gender,course_name,course_no)
VALUES
(2,"Mike","Male","OOP",123);
select * from student;
select stud_id,stud_name,course_name
from student;
/* task:
insert the following records into student table:
3   Sana    Female  OOP 123
4   Hira    Female  OOP 123
5   David   Male    DB  321
*/
/* task:
Customer table                      
                        
cut_id  cust_name   city    state   zip_code    country phone_no
1   ABC Las Vegas   NM  87701   USA 123-456-1111
2   ADE Las Cruces  NM  88001   USA 321-456-1234
3   XYZ Santa Fe    NM  87501   USA 123-654-4321
*/
-- https://gist.github.com/nmsmith22389/69271303e107f1a4a0d5bcaaacafadf3
-- Sales
/*                  0       
sale_id cust_fname  cust_lname  unit_price  total_qnty  total_price cust_address    shipping_status
1   Mike    Steven  5.23    9   47.07   Las vegas NM    Y
2   Ponting Ricky   23.6    10  236 Santa Fe NM Y
3   Brain   Lara    1.2 7   8.4 Austin TX   N
4   Zain    M   0.2 45  9   Dallas TX   Y
*/
CREATE TABLE sales (
sale_id INT,
cust_fname VARCHAR(256),
cust_lname VARCHAR(256),
unit_price DECIMAL(10,2),
total_qnty INT,
total_price DECIMAL(10,2),
cust_address VARCHAR(265),
ship_status CHAR(1));
select * from sales;
INSERT INTO sales (sale_id, cust_fname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(1,"Mike","Steven",5.23,9,47.07,"Las Vegas NM","Y");
INSERT INTO sales (sale_id, cust_fname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(2,"Ponting","Ricky",23.6,10,236,"Santa Fe NM","Y");
INSERT INTO sales (sale_id, cust_fname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(3,"Brain","Lara",1.2,7,8.4,"Austin Tx","N");
INSERT INTO sales (sale_id, cust_fname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(4,"Zain","M",.2,45,9,"Dallas Tx","Y");
select * from sales;
/*******************************************************************************************/
/*
task:
SalesTable                      0       
sale_id cust_fname  cust_mname  cust_lname  unit_price  total_qnty  #VALUE! cust_address    shipping_status
1   Mike    A   Steven  5.23    9   47.07   Las vegas NM    Y
2   Ponting B   Ricky   23.6    10  236 Santa Fe NM Y
3   Brain       Lara    1.2 7   8.4 Austin TX   N
4   Zain    BH  M   0.2 45  9   Dallas TX   Y
*/
CREATE TABLE sales_table (
sale_id INT,
cust_fname VARCHAR(256),
cust_mname VARCHAR(256),
cust_lname VARCHAR(256),
unit_price DECIMAL(10,2),
total_qnty INT,
total_price DECIMAL(10,2),
cust_address VARCHAR(265),
ship_status CHAR(1));
select * from sales_table;
INSERT INTO sales_table (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(1,"Mike","A","Steven",5.23,9,47.07,"Las Vegas NM","Y");
INSERT INTO sales_table (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(2,"Ponting","B","Ricky",23.6,10,236,"Santa Fe NM","Y");
INSERT INTO sales_table (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(3,"Brain"," ","Lara",1.2,7,8.4,"Austin Tx","N");
INSERT INTO sales_table (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(4,"Zain","AB","M",.2,45,9,"Dallas Tx","Y");
select * from sales_table;
/*******************************************************************************************************/
-- you should use the key word of null/not null against every field(this is the good practice to create the table)
CREATE TABLE sales_tablenew (
sale_id INT NOT NULL,
cust_fname VARCHAR(256) NOT NULL,
cust_mname VARCHAR(256) NULL,
cust_lname VARCHAR(256) NOT NULL,
unit_price DECIMAL(10,2) NOT NULL,
total_qnty INT NOT NULL,
total_price DECIMAL(10,2) NOT NULL,
cust_address VARCHAR(265) NOT NULL,
ship_status CHAR(1) NOT NULL);
INSERT INTO sales_tablenew (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(1,"Mike","A","Steven",5.23,9,47.07,"Las Vegas NM","Y");
INSERT INTO sales_tablenew (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(2,"Ponting","B","Ricky",23.6,10,236,"Santa Fe NM","Y");
INSERT INTO sales_tablenew (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(3,"Brain"," ","Lara",1.2,7,8.4,"Austin Tx","N");
INSERT INTO sales_tablenew (sale_id, cust_fname,cust_mname,cust_lname,unit_price,total_qnty,total_price,cust_address,ship_status)
VALUES
(4,"Zain","AB","M",.2,45,9,"Dallas Tx","Y");
select * from sales_tablenew;
 
No comments:
Post a Comment