0% found this document useful (0 votes)
9 views

activity2_batch2

The document outlines the creation and manipulation of a MySQL database named 'activity2', including the creation of a 'CUSTOMER' table with various attributes. It details the insertion of customer records, modifications to the table structure, and various SQL queries to retrieve and manipulate data. Additionally, it demonstrates the use of functions like REPLACE, POSITION, and CONCAT in SQL queries.

Uploaded by

ares.g1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

activity2_batch2

The document outlines the creation and manipulation of a MySQL database named 'activity2', including the creation of a 'CUSTOMER' table with various attributes. It details the insertion of customer records, modifications to the table structure, and various SQL queries to retrieve and manipulate data. Additionally, it demonstrates the use of functions like REPLACE, POSITION, and CONCAT in SQL queries.

Uploaded by

ares.g1202
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

mysql> create database activity2;

mysql> use activity2;


Database changed

2-4.
mysql> create table CUSTOMER(
-> CUST_CODE VARCHAR(6),
-> CUST_NAME VARCHAR(25) NOT NULL,
-> CUST_CITY CHAR(35) NOT NULL,
-> WORKING_AREA VARCHAR(5) NOT NULL,
-> CUST_COUNTRY VARCHAR(20) NOT NULL,
-> PHONE_NO VARCHAR(15) NOT NULL
-> );

5.
mysql> ALTER TABLE CUSTOMER
-> ADD PRIMARY KEY(CUST_CODE);

6-9.
mysql> INSERT INTO CUSTOMER VALUES
-> ("C001","John Smith","London","Sales","US","1234567890"),
-> ("C002","Alice Johnson","New York","Admin","UK","9876543210"),
-> ("C003","Carlos Lopez","Madrid","Tech","Spain","1122334455"),
-> ("C004","Wei Zheng","Shanghai","HR","China","6677889900"),
-> ("C005","Emma Brown","Sydney","Sales","Autralia","9988776655");

10.
mysql> SELECT REPLACE("bam is very angry because bam is short-
tempered","bam","boom");

11.
mysql> SELECT POSITION("mo" in "Sana sinabi mo para may tayo pa sa huli");

12.
mysql> SELECT CONCAT("wag ka nang mawala"," ","ngaayooon, dadalhin kita sa aming
bahay");

13-15.
mysql> SELECT CUST_CODE,CUST_NAME,CUST*,
-> REVERSE(CUST_NAME) AS customer_rev_name,
-> COUNT(CUST_CODE) AS customer_count_code
-> FROM CUSTOMER
-> GROUP BY CUST_CODE,CUST_NAME,CUST_CITY,WORKING_AREA,CUST_COUNTRY,PHONE_NO
-> ORDER BY CUST_NAME;

16.
mysql> ALTER TABLE CUSTOMER
-> ADD CUST_AGE INT(10);

17.
mysql> ALTER TABLE CUSTOMER
-> DROP CUST_COUNTRY;

mysql> ALTER TABLE CUSTOMER


-> ADD COUNTRY VARCHAR(20);

18.
mysql> TRUNCATE TABLE CUSTOMER;

19.
mysql> INSERT INTO CUSTOMER VALUES
-> ("C001","John Smith","London","Sales","1234567890",29,"US"),
-> ("C002","Alice Johnson","New York","Admin","9876543210",28,"UK"),
-> ("C003","Carlos Lopez","Madrid","Tech","1122334455",27,"Spain"),
-> ("C004","Wei Zheng","Shanghai","HR","6677889900",26,"China"),
-> ("C005","Emma Brown","Sydney","Sales","9988776655",25,"Autralia"),
-> ("c012","ralph","","","",24,"");

20-22.
mysql> SELECT CUST_CODE, PHONE_NO as cp_number,
-> COUNT(CUST_CITY) AS city_count,
-> COUNT(COUNTRY) AS country_count
-> FROM CUSTOMER
-> GROUP BY CUST_CODE, PHONE_NO
-> ORDER BY CUST_CODE DESC;
+-----------+------------+------------+---------------+
| CUST_CODE | cp_number | city_count | country_count |
+-----------+------------+------------+---------------+
| c012 | | 1 | 1 |
| C005 | 9988776655 | 1 | 1 |
| C004 | 6677889900 | 1 | 1 |
| C003 | 1122334455 | 1 | 1 |
| C002 | 9876543210 | 1 | 1 |
| C001 | 1234567890 | 1 | 1 |
+-----------+------------+------------+---------------+
6 rows in set (0.00 sec)

26-27.
mysql> SELECT CUST_CODE, CUST_NAME, PHONE_NO
-> FROM CUSTOMER
-> WHERE WORKING_AREA = 'Sales';
29. +-----------+------------+------------+
| CUST_CODE | CUST_NAME | PHONE_NO |
+-----------+------------+------------+
| C001 | John Smith | 1234567890 |
| C005 | Emma Brown | 9988776655 |
+-----------+------------+------------+
2 rows in set (0.00 sec)

30.
mysql> show tables;
+---------------------+
| Tables_in_activity2 |
+---------------------+
| customer |
+---------------------+
1 row in set (0.00 sec)

You might also like