MySQL数据库3.4上计实践:图书表的数据操作代码
时间: 2023-08-02 16:05:42 浏览: 119
SSH框架的整合
以下是一个基本的图书表(Book)的数据操作代码示例,包括创建表、插入数据、查询数据、更新数据和删除数据等操作。
创建表:
```
CREATE TABLE Book (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
author VARCHAR(50) NOT NULL,
publisher VARCHAR(50) NOT NULL,
price DECIMAL(10,2) NOT NULL,
PRIMARY KEY (id)
);
```
插入数据:
```
INSERT INTO Book (title, author, publisher, price)
VALUES ('The Great Gatsby', 'F. Scott Fitzgerald', 'Charles Scribner\'s Sons', 9.99),
('To Kill a Mockingbird', 'Harper Lee', 'J. B. Lippincott & Co.', 8.95),
('1984', 'George Orwell', 'Secker & Warburg', 10.99),
('The Catcher in the Rye', 'J. D. Salinger', 'Little, Brown and Company', 7.99);
```
查询数据:
```
SELECT * FROM Book;
```
更新数据:
```
UPDATE Book
SET price = 12.99
WHERE title = 'The Great Gatsby';
```
删除数据:
```
DELETE FROM Book
WHERE author = 'J. D. Salinger';
```
阅读全文