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

database

The document outlines SQL commands for managing a 'books' table, including creating the table, inserting data, altering its structure, updating records, and deleting entries. It also includes queries to select and sort data based on specific criteria. The table is eventually renamed to 'library_books' for better categorization.

Uploaded by

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

database

The document outlines SQL commands for managing a 'books' table, including creating the table, inserting data, altering its structure, updating records, and deleting entries. It also includes queries to select and sort data based on specific criteria. The table is eventually renamed to 'library_books' for better categorization.

Uploaded by

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

1.

CREATE TABLE books (

book_id INT PRIMARY KEY,

title VARCHAR(100),

author VARCHAR(50),

price DECIMAL(10,2),

genre VARCHAR(50)

);

2.

INSERT INTO books (book_id, title, author, price, genre)

VALUES

(1, 'The Great Gatsby', 'F. Scott Fitzgerald', 299.99, 'Fiction'),

(2, 'To Kill a Mockingbird', 'Harper Lee', 199.99, 'Fiction'),

(3, 'A Brief History of Time', 'Stephen Hawking', 349.99, 'Science'),

(4, '1984', 'George Orwell', 149.99, 'Dystopian'),

(5, 'Pride and Prejudice', 'Jane Austen', 249.99, 'Romance');

select* from books ;

3.
ALTER TABLE books ADD COLUMN publication_year INT;

select* from books ;

ALTER TABLE books CHANGE COLUMN genre category VARCHAR(50);

select * from books;

4.

UPDATE books SET price = price * 1.10;

select * from books ;

UPDATE books SET author = 'New Author' WHERE book_id = 3;

select* from books ;

5.

DELETE FROM books WHERE publication_year < 2000;

select * from books;

6.

ALTER TABLE books RENAME TO library_books;

7.

SELECT * FROM library_books WHERE category = 'Fiction' ORDER BY price


DESC;

8.

SELECT title, price FROM library_books ORDER BY price DESC LIMIT 1;

You might also like