Write a query to store and retrieve book information in the database (DBMS)?


Use the create command to create a table. Insert the values that are book information into the created database table using insert command.

If we want to view or retrieve the inserted data use the select command.

Step 1

Create a book table in database as follows −

The create command is used to create table, view, index

Syntax

The syntax for the create command is as follows −

Create table tablename(col1 datatype(size), col2 datatype(size),……….colN datatype(size));

Example

Use the below mentioned command −

create table book (bookname varchar(30), authorname varchar(30), noofcopies number(20));

The output is the table created as shown below −

BooknameAuthornamenoofcopies

Step 2

Describe − The command used to describe the table is desc

Syntax

The syntax for the describe command is as follows −

desc tablename

Example

Use the command given below −

desc book

Output

NameNULLType
bookname
varchar(30)
authorname
varchar(30)
noofcopies
varchar(20)

Step 3

Insert − The command used to insert data into table/view/index in database using ‘insert’.

Syntax

The syntax for the insert command is as follows −

insert into tablename values(valu1,value2,value3,……valueN);

Example

  • Insert into book values (‘DBMS’,’korth’ ,20); Output: 1 row created.

  • Insert into book values (‘DAA’,’cormen’, 30); Output: 1 row created.

  • Insert into book values (‘system programming’,’j.j.donovan’, 40); Output: 1 row created.

Step 4

Select − The command used to select columns is select.

The syntax for the select command is given below −

select column1, column2,…….coulmnN from tablename

Example

Use the following command −

select distinct * from book;

Description − It displays distinct names in sorted order.

Output

BooknameAuthornameNoofcopies
DAACormen20
DBMSKorth30
System programmingj.j.donovan40

Step 5

Select lower (bookname) from book;

Description − Display bookname field in lower case letter.

Output

LOWER(BOOKNAME)
daa
dbms
system programming

Step 6

Select upper (authorname) from book;

Description − It displays the author name field in uppercase letter.

Output

UPPER(AUTHORNAME)
KORTH
JJ DONOVAN
CORMEN

Updated on: 06-Jul-2021

676 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements