0% found this document useful (0 votes)
74 views5 pages

Assignment-Ii: Inserting A Single Row Into A Table

This document contains an assignment on Data Manipulation Language (DML) commands in SQL. It begins with explanations and examples of the INSERT, SELECT, UPDATE, and DELETE commands. It then lists 14 problems to solve using DML commands on sample dept and emp tables. The problems involve tasks like inserting records, selecting records with various filters, ordering results, and joining tables. The document provides the necessary table structures and sample data to complete the assignment problems.

Uploaded by

Krishnendu Guin
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)
74 views5 pages

Assignment-Ii: Inserting A Single Row Into A Table

This document contains an assignment on Data Manipulation Language (DML) commands in SQL. It begins with explanations and examples of the INSERT, SELECT, UPDATE, and DELETE commands. It then lists 14 problems to solve using DML commands on sample dept and emp tables. The problems involve tasks like inserting records, selecting records with various filters, ordering results, and joining tables. The document provides the necessary table structures and sample data to complete the assignment problems.

Uploaded by

Krishnendu Guin
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/ 5

8/2/2021 ASSIGNMENT-II

ASSIGNMENT-II

Due
16 Jul by 1:59
Points
0
Submitting
a file upload
Available
7 Jul at 2:00 - 16 Jul at 1:59
9 days

This assignment was locked 16 Jul at 1:59.


2. Data Manipulation Language (DML) commands in RDBMS

DML commands are the most frequently used SQL commands and is used to query and manipulate
the existing database objects. Some of the commands are:

Insert
Select
Update
Delete
Insert Command

This is used to add one or more rows to a table. The values are separated by commas and the data
types char and date are enclosed in apostrophes. The values must be entered in the same order as
they are defined.

Inserting a single row into a table:

Syntax: insert into <table name> values (value list)

Example: insert into s values (‘s3’,’sup3’,’blore’, 10)

Inserting more than one record using a single insert commands:

Syntax: insert into <table name> values (&col1, &col2, ….)

Example: Insert into stud values(&reg, ‘&name’, &percentage);

Skipping the fields while inserting:

Insert into <tablename(coln names to which datas to b inserted)> values (list of values);

Other way is to give null while passing the values.

Select Commands
https://canvas.instructure.com/courses/2858741/assignments/23280198 1/5
8/2/2021 ASSIGNMENT-II

It is used to retrieve information from the table.it is generally refered to as querying the table.We can
either display all columns in a table or only specify column from the table.

Syntax: Select * from tablename; // This query selects all rowsfrom the table.

Example; Select * from IT;

The retrieval of specific columns from a table:

It retrieves the specified columns from the table

Syntax: Select column_name1, ….., column_namen from table name;

Example: Select empno, empname from emp;

Elimination of duplicates from the select clause:

It prevents retriving the duplicated values .Distinct keyword is to be used.

Syntax: Select DISTINCT col1, col2 from table name;

Example: Select DISTINCT job from emp;

Select command with where clause:

To select specific rows from a table we include ‘where’ clause in the select command. Itcan appear
only after the ‘from’ clause.

Syntax: Select column_name1 , ..….., column_namen from table name where condition;

Example: Select empno, empname from emp where sal>4000;

Select command with order by clause:

Syntax: Select column_name1, …..,column_namen from table name where condition order

by colmnname;

Example: Select empno, empname from emp order by empno;

Select command to create a table:


Syntax: create table tablename as select * from existing_tablename;

Example: create table emp1 as select * from emp;

Select command to insert records:

Syntax: insert into tablename ( select columns from existing_tablename);

Example: insert into emp1 ( select * from emp);


https://canvas.instructure.com/courses/2858741/assignments/23280198 2/5
8/2/2021 ASSIGNMENT-II

Update Command

It is used to alter the column values in a table. A single column may be updated or more than one
column could be updated.

Syntax: update tablename set field=values where condition;

Example: Update emp set sal = 10000 where empno=135;

Delete command

After inserting row in a table we can also delete them if required. The delete command consists of a
from clause followed by an optional where clause.

Syntax: Delete from table where conditions;

Example:delete from emp where empno=135;

ASSIGNMENT-II

Problem 2.1: Insert 5 records into dept table.

DEPTNO DNAME DLOC

10 MANAGEMENT MAIN BLOCK

20 DEVELOPMENT MANUFACTURING UNIT

30 MAINTAINANCE MAIN BLOCK

40 TRANSPORT ADMIN BLOCK

50 SALES HEAD OFFICE

Problem 2.2: Insert 11 records into emp table.

EMPNO ENAME JOB MGR DOB SAL COMM DEPTNO

7369 SMITH CLERK 7566 17-DEC-80 800 0 20

https://canvas.instructure.com/courses/2858741/assignments/23280198 3/5
8/2/2021 ASSIGNMENT-II

7399 ASANT SALESMAN 7566 20-FEB-81 1600 300 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30

7521 WARD SALESMAN 7698 22-FEB-82 1250 500 30

7566 JONES MANAGER 7839 02-APR-81 5975 500 20

7698 BLAKE MANAGER 7839 01-MAY-79 9850 1400 30

7611 SCOTT HOD 7839 12-JUN-76 3000 0 10

7839 CLARK CEO NULL 16-MAR-72 9900 0 10

7368 FORD SUPERVIS 7366 17-DEC-80 8000 0 20

7599 ALLEY SALESMAN 7698 20-FEB-81 1600 300 30

7421 DRANK CLERCK 7698 22-JAN-82 1250 500 30

Problem 2.2: Find the name of all employees.

Problem 2.3: Delete only those who are working as supervisors.

Problem 2.4: Delete the rows whose empno is 7599.

Problem 2.5: List the records in the emp table order by salary in ascending order.

Problem 2.6: List the records in the emp table orderby salary in descending order.

Problem 2.7: Display only those employees whose deptno is 30.

Problem 2.8: Display deptno from the table employee avoiding the duplicated values.

Problem 2.9: List the records in sorted order of their employees.

Problem 2.10: List the employee names whose commission is null.

Problem 2.11: List the employee names and the department name in which they are working. 

Problem 2.12: Display name of the dept. with deptno 20. 

Problem 2.13: List ename whose commission is NULL 

Problem 2.14: List ename whose manager is not NULL.


https://canvas.instructure.com/courses/2858741/assignments/23280198 4/5
8/2/2021 ASSIGNMENT-II

https://canvas.instructure.com/courses/2858741/assignments/23280198 5/5

You might also like