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

MySQL Solution 1st 5 Worksheets

This document contains examples of SQL commands for creating databases and tables, modifying table structures, inserting, updating, and deleting records. It includes commands for creating databases and tables, setting primary keys and constraints, inserting data, updating field values, deleting records, and altering table structures. The document appears to be part of a series of worksheets intended to teach basic to intermediate SQL skills.

Uploaded by

navya chawla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

MySQL Solution 1st 5 Worksheets

This document contains examples of SQL commands for creating databases and tables, modifying table structures, inserting, updating, and deleting records. It includes commands for creating databases and tables, setting primary keys and constraints, inserting data, updating field values, deleting records, and altering table structures. The document appears to be part of a series of worksheets intended to teach basic to intermediate SQL skills.

Uploaded by

navya chawla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

My SQL Worksheet-1

(DDL – Database Related commands)


1 Use Employee.

2 Use Library.

3 Use database name.

4 SQL Stands for structured query language.


MySQL is an open-source RDBMS (Relational Database Management System)

5 SQL Server, My SQL, Oracle, Ingres, Postgres

6 Use Company.

7 MySQL is an open-source RDBMS (Relational Database Management System)


8 SQL is a language to give commands in MySQL or any other RDBMS software.

9 SQL Server, Ingres, Postgres, MySQL

10 i. Show Databases.
ii. Use City.
iii. Drop database clients.

11 Select Database ().

12 Create database school.


My SQL Worksheet-2
(DDL – Table Related commands excluding Alter table)
1 Create table Menu (
Item Code varchar (5) Primary key,
Item name varchar (20),
Category Varchar (20),
Price Decimal (5,2));
2 No, a table cannot have multiple primary keys. There can only be one primary key.
Yes, a table can a multiple foreign key.

3 Roll Number can be set as Primary Key as two students cannot have a same roll number.

4 Drop Table Backup.

5 Create table Stock (


Id Decimal (4) Primary Key,
Name Varchar (20),
Company Varchar (20),
Price Decimal (8) Not Null);
6 Similarity:
Both char and varchar can store alphabets as well as numbers. Both can store same type of
values.

Difference:
Char is a fixed length character datatype whereas varchar is a variable length character
datatype.

7 Describe Product.

8 Use Gadgets.
Show tables.
9 i) Drop table name.
ii) Describe table name.
10 Similarity:
Both Unique and primary key restricts duplicate values in the field.
Difference:
Unique allows null values whereas Primary does not allow null values to be inserted in the
field.
11 A will occupy 4-character space.
B will occupy 20-character space.
12 i) Roll No and Name can be the attributes of student table.
ii) Roll No can become the primary key of the student table as two students cannot
have a same roll number.
13 Create table Player (
Player id integer primary key,
Name varchar (50),
Height integer,
Weight integer,
Date birth date,
Team name varchar (50)).
14 i)The datatype for order ID field can be either char or varchar
The datatype for order Date is date
ii) She will not be able to insert the above record as she is inserting a null value in the
order date field and the order date field have a not null constraint which cannot accept
null values.
15 Create table Event (
Event ID varchar (5) Primary Key,
Event Name varchar (30) not null,
Location varchar (50),
Client ID Integer,
Event Date
16 i. Pan No might have a Primary Key constraint as two persons cannot have a same
Pan Number.
ii. Phone No might have a unique constraint as two persons will be having different
mobile numbers.
17 Create table Event (
Event ID Integer Primary Key,
Event Varchar (5 0),
Date Event Date,
Num Performers Integer)
18 i. Show databases.
ii. Use City.
iii. Drop database Clients.
iv. Drop table Club.
19 EName field can have a varchar as a datatype as two employees will not be having a same
length of their names.
My SQL Worksheet-3
(DDL – Table Related commands)
1 Alter table name add fieldname datatype(size).

2 Alter table customer add primary key (cust id).

3 Alter table hospital add address varchar (30).

4 Alter table student drop hobbies.

5 Alter table student add game_played varchar (30).

6 Alter table friends drop hobbies.

7 Alter table student add hobbies varchar (50).


8 Alter table employee add primary key(empid).

9 Alter table customer ass primary key (cust name).

10 Alter table employee modify name varchar (30) null.


My SQL Worksheet-4
(DML – INSERT INTO commands)
1 Not Null, Primary Key

2 Insert into Result values (6, "Mohan", 500, "English", 73, "Second").

3 Insert into Result values ('110', 'Pizza’, 'Papa Jones', 120, "Kolkata", 50.0).

4 Null means no value whereas 0 is a value.

5 Insert into Result values ("G107", "Vibro exerciser” ,21000, “GTCFitness").

6 Null means no value

7 INSERT INTO STUDENT (RNO, MARKS) VALUES (5,78.5).

8 INSERT INTO EMP (EMPNO, SALES) VALUES (100, 20078.50).

9 INSERT INTO Emp (Last Name) VALUES(‘Sharma’).

10 i)The datatype for order ID field can be either char or varchar


The datatype for order Date is date
ii) She will not be able to insert the above record as she is inserting a null value in the
order date field and the order date field have a not null constraint which cannot
accept null values.

11 i. DML ii. DDL

12 No null is not same as 0. Null means no value. 0 is a value.


Any numerical calculation on null will give null
Any numerical calculation on 0 will do the actual calculation.

13 i. Data Definition Language


ii. Data Manipulation Language
My SQL Worksheet-5
(DML – UPDATE and DELETE commands)
1 Drop table deletes the table along with the structure. Delete deletes the records.

2 Update Product set price=price + 20.

3 Update Employee set Last name=” Singh” where last name=” Sharma”;

4 Update command updates the records.


Alter command modifies the structure of the table.

5 Update Gym set brand name=” Fit Trend India” where I code=” G101”.

6 Update emp set commission=commission + 100.00.

7 Insert, Update, delete, select

8 Update CD set singer=” Sonvi Mehra” where singer=” Sonvi Kumar”.

9 1) Update Garment set colour=” Orange” where Gcode=116.


2) Update Garment set price=price+price*10/100 where size=” XL”.
3) Delete from garment where gcode=116;
10 Update employee set job id=104 where employee ID=” E4”.

11 Update student set marks=marks-5 where roll number=2.

12 Update orders set sales amount=salesamount+20’

13 Update Pharma DB set price=price+50 where drug name=” Amlodipine”.

You might also like