0% found this document useful (0 votes)
35 views2 pages

Untitled

The document contains instructions and examples for SQL exercises focused on creating databases and tables, inserting, updating, deleting and selecting data using queries. It includes examples of creating a userinfo table, inserting, updating and deleting records, creating a usertable with various fields, adding and removing columns from the table, and deleting the table. It also provides CRUD queries examples to create, select, update and delete records in the usertable. Finally, it lists exercises for students to create tables to store customer, book and food information, and create databases with related tables for online grocery, food ordering app and library management systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Untitled

The document contains instructions and examples for SQL exercises focused on creating databases and tables, inserting, updating, deleting and selecting data using queries. It includes examples of creating a userinfo table, inserting, updating and deleting records, creating a usertable with various fields, adding and removing columns from the table, and deleting the table. It also provides CRUD queries examples to create, select, update and delete records in the usertable. Finally, it lists exercises for students to create tables to store customer, book and food information, and create databases with related tables for online grocery, food ordering app and library management systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

11/2/21, 7:21 PM https://macappstudiobridge.com/SQL_Exercise.

txt

Class #3.2 : MYSQL Database Demo - How to create database, tables and run queries.

**********************************************************************************

Worksheet and Exercises:

========================

SQL Exercise Queries:

Set 1:

------

INSERT INTO `userinfo` (`user_id`, `name`, `email`, `password`) VALUES ('2', 'selva',
'[email protected]', 'test12');

SELECT * FROM userinfo

UPDATE `userinfo` SET `password` = 'password12' WHERE `user_id` = 1;

DELETE FROM `userinfo` WHERE `userinfo`.`user_id` = 2;

Set 2:

------

Query 1 - Create a table:

CREATE TABLE `usertable` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(100) NOT NULL ,
`username` VARCHAR(100) NOT NULL , `password` VARCHAR(100) NOT NULL , `city` VARCHAR(100) NOT NULL
, `age` VARCHAR(100) NOT NULL , `gender` VARCHAR(100) NOT NULL , PRIMARY KEY (`id`));

Query 2 - Alter a table to add a column:

ALTER TABLE `usertable` ADD `yearofbirth` INT NOT NULL AFTER `city`;

Query 3- Alter table to remoove the column:

ALTER TABLE `usertable` DROP `yearofbirth`;

Query 4 - Delete a table:

DROP TABLE usertable;

Note : The drop query will delete the table. You need to do the run the create query alone again
to proceed further.

CRUD Queries for Records:

-------------------------

Queury 1 - Create a new user record :

INSERT INTO `usertable` (`id`, `name`, `username`, `password`, `city`, `age`, `gender`) VALUES (1,
'User 1', '[email protected]', '123456', 'Chennai', '25', 'Male')

Query 2 - Select a user record with a particular user name and password:

SELECT * FROM `usertable` WHERE `username`='[email protected]' AND `password`='123456'

Query 3 - Update a user record:

UPDATE `usertable` SET `password`='password12' WHERE `username`='[email protected]'

Query 4 - Delete a user record:

DELETE FROM `usertable` WHERE `username`='[email protected]'

Resources:

SQL Tutorial Links : https://www.w3schools.com/sql/default.asp

https://macappstudiobridge.com/SQL_Exercise.txt 1/2
11/2/21, 7:21 PM https://macappstudiobridge.com/SQL_Exercise.txt

SQL Exercise Links : https://www.w3schools.com/sql/exercise.asp?filename=exercise_select1

SQL Joins Overview : https://www.w3schools.com/sql/sql_join.asp

Exercises:

Tables:

Create one table in the following requirement:

1. Create a table for storing only customer information of a grocery store.

2. Create a table for storing only book information in a library

3. Create a table for storing only food information in a food ordering app

Database:

Create a set of tables for each database in the following requirement:

1. Create a database with a set of tables for online grocery store management

2. Create a database with a set of tables for a food ordering app

3. Create a database with a set of tables for a library management system

https://macappstudiobridge.com/SQL_Exercise.txt 2/2

You might also like