MySQL是一種流行的關系型數據庫管理系統,它可以用于多種應用程序,包括圖書信息管理。在本文中,我們將介紹如何使用MySQL創建一個圖書數據庫表。
CREATE TABLE books ( id INT NOT NULL PRIMARY KEY, title VARCHAR(255) NOT NULL, author VARCHAR(255) NOT NULL, publisher VARCHAR(255) NOT NULL, publication_date DATE NOT NULL, description TEXT, price DECIMAL(10,2) NOT NULL );
首先,我們需要使用CREATE TABLE語句創建一個名為books的表。在這個表中,我們定義了七個列,分別是id、title、author、publisher、publication_date、description和price。
id列是一個整數列,用作主鍵,每個記錄都必須具有唯一id值。title、author和publisher列都是字符串列,表示圖書的標題、作者和出版商。publication_date列是一個日期列,表示圖書的出版日期。description列是一個文本列,用于描述圖書。price列是一個十進制列,用于表示圖書的價格。
INSERT INTO books (id, title, author, publisher, publication_date, description, price) VALUES (1, 'The Great Gatsby', 'F. Scott Fitzgerald', 'Scribner', '1925-04-10', 'The Great Gatsby, F. Scott Fitzgerald’s third book, stands as the supreme achievement of his career. ', 15.99), (2, 'To Kill a Mockingbird', 'Harper Lee', 'J. B. Lippincott & Co.', '1960-07-11', 'To Kill a Mockingbird is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.', 12.50), (3, 'Pride and Prejudice', 'Jane Austen', 'T. Egerton, Whitehall', '1813-01-28', 'Pride and Prejudice is a romantic novel of manners written by Jane Austen in 1813. The novel follows the character development of Elizabeth Bennet, the dynamic protagonist of the book.', 9.99);
接下來,我們可以使用INSERT INTO語句向books表中添加一些示例數據。
使用以上代碼,我們可以成功創建一個名為books的表,并向其中添加了三本圖書的示例數據。
上一篇c json批量數據庫
下一篇vue circle