勤奋、好学、不矜、不骄才是好女子

mysql各种操作实例

上一篇 / 下一篇  2010-01-06 11:29:29 / 个人分类:数据库相关知识

一:创建数据库
create table customers
(customerid int unsigned not null auto_increament primary key,
  name char(50)not null,
  address char(100) not null,
  city char(30) not null
);
create table orders
(orderid int unsigned not null auto_increament primary key,
  customerid int unsigned not null,
  amount float(6,2),
  date date not null
);
create table books
(isbn char(13)not null primary key,
  author char(50),
  title char(100),
  price float(4,2),
);
create table order_items
( orderid int unsigned not null,
   isbn char(13) not null,
   quantity tinyint unsigned,
   primary key (orderid,isbn)
);
create table book_reviews
(isbn char(13) not null primary key,
  reviews text
);
二:查看数据库、表
mysql>show tables;
mysql>show books;
三:向数据库中的表插入数据
insert into customers values
(3,’julie smith‘,’25 oak
insert into orders VALUES
( null,3,69.98,'2007-04-02'),
( null,1,49.99,'2007-04-15'),
( null,2,74.98,'2007-04-19'),
( null,3,24.99,'2007-05-01');
SELECT * from orders;
insert into books VALUES
('0-672-31697-8','michael morgan','java 2 for professional developers',34.99),
('0-672-31745-1','thomas down','installing debian gnu/linux',24.99),
('0-672-31509-2','pruitt et al.','teach yourself gimp in 24 hours',24.99),
('0-672-31769-9','thomas schenk','caldera openlinux system administration unleashed',49.99);
select * from books;
INSERT into order_items values
(1,'0-672-31697-8',2),
(2,'0-672-31769-9',1),
(3,'0-672-31769-9',1),
(3,'0-672-31509-2',1),
(4,'0-672-31745-1',3);

TAG:

 

评分:0

我来说两句

Open Toolbar