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

Rdbms Lab Exercise

The document outlines a procedure to create a database and two tables, 'library' and 'library1', with specified fields. It includes steps for inserting records into the 'library' table, creating a view to select data from 'library', and inserting that data into 'library1'. The process concludes with verifying the data in 'library1' and confirms successful execution of the SQL queries.

Uploaded by

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

Rdbms Lab Exercise

The document outlines a procedure to create a database and two tables, 'library' and 'library1', with specified fields. It includes steps for inserting records into the 'library' table, creating a view to select data from 'library', and inserting that data into 'library1'. The process concludes with verifying the data in 'library1' and confirms successful execution of the SQL queries.

Uploaded by

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

Ex.No.

6 TABLE CREATION WITH VIEWS

Statement of problem
create a table ‘ library’ with proper fields and create another table ‘ library1’ and insert
rows from library using views

Aim
To create a table ‘ library’ with proper fields and create another table ‘ library1’ and insert
rows from library using views

PROCEDURE:
Create Database
 CREATE DATABASE lib_db;
show the database
 SHOW DATABASES;
Using the database
 USE lib_db;

Create the 'library' table


 CREATE TABLE library
(
book_id INT PRIMARY KEY,
book_title VARCHAR(255),
author VARCHAR(255),
genre VARCHAR(255),
publication_year INT,
available BOOLEAN
);
 Desc library;
Insert some records into the 'library' table
 INSERT INTO library (book_id, book_title, author, genre, publication_year, available)
VALUES
(1, 'The Lord of the Rings', 'J.R.R. Tolkien', 'Fantasy', 1954, TRUE),
(2, 'Pride and Prejudice', 'Jane Austen', 'Romance', 1813, FALSE),
(3, 'To Kill a Mockingbird', 'Harper Lee', 'Historical Fiction', 1960, TRUE),
(4, '1984', 'George Orwell', 'Dystopian', 1949, FALSE),
(5, 'The Hitchhiker's Guide to the Galaxy', 'Douglas Adams', 'Science Fiction', 1979,
TRUE);

Selecting the table


 select * from library;

Create the 'library1' table with the same structure as 'library'


 CREATE TABLE library1
(
book_id INT PRIMARY KEY,
book_title VARCHAR(255),
author VARCHAR(255),
genre VARCHAR(255),
publication_year INT,
available BOOLEAN
);
Create a view to select all data from the 'library' table
 CREATE VIEW library_view AS SELECT * FROM library;

Insert data from the 'library_view' into the 'library1' table


 INSERT INTO library1 SELECT * FROM library_view;
Verify the data in 'library1'
 SELECT * FROM library1;

Result
The mysql query to create a table ‘ library’ with proper fields and create another table ‘
library1’ and insert rows from library using views has been done successfully.
OUTPUT:

Library Table structure:

Displaying Library Records:


Library1 Table Structure:

Displaying Library1 Records:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy