mysql
в пакетном режимеBuy this Reference Manual in softcover from Barnes & Noble!
Здесь представлены примеры решения некоторых стандартных задач средствами MySQL.
В некоторых из примеров используется таблица shop
(магазин), в которой содержатся цены по каждому изделию (item number
)для определенных продавцов (dealer
). Предположим, что каждый продавец имеет одну фиксированную цену для каждого изделия; тогда пара изделие-продавец (article, dealer
) является первичным ключом для записей таблицы.
Запустите клиента mysql
:
mysql имя-вашей-базы-данных
(Для большинства инсталляций MySQL можно использовать базу данных 'test
'.)
Таблицу примера можно создать таким образом:
CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL, dealer CHAR(20) DEFAULT '' NOT NULL, price DOUBLE(16,2) DEFAULT '0.00' NOT NULL, PRIMARY KEY(article, dealer)); INSERT INTO shop VALUES (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69), (3,'D',1.25),(4,'D',19.95);
Ну и, скажем, данные для примера будут такими:
mysql> SELECT * FROM shop; +---------+--------+-------+ | article | dealer | price | +---------+--------+-------+ | 0001 | A | 3.45 | | 0001 | B | 3.99 | | 0002 | A | 10.99 | | 0003 | B | 1.45 | | 0003 | C | 1.69 | | 0003 | D | 1.25 | | 0004 | D | 19.95 | +---------+--------+-------+
Posted by on Tuesday October 15 2002, @4:40am | [Delete] [Edit] |
I promise this is the last time I'll do this, as it's sure
to be annoying for others, but ... here's some info
for other newbies (please feel free to correct
any mistakes): INT(N) is an integer with up to N
digits; UNSIGNED means that the integer cannot be
preceded by a symbol/sign, thus it can't be a
negative integer; ZEROFILL means that the entry will
be automatically extended to N digits using zeroes
added to the left of the number; DEFAULT '' defines
the 'zero' entry, i.e. the entry that MySQL will make
automatically, should no integer be entered; NOT
NULL means that each row must have an entry in
this column, i.e. it can't be empty; CHAR(N) you've
met already, but it is CHAR and not VARCHAR in this
case so that each entry will be numerically identical
(20 bytes in this case) and can be used in a
comparison; DOUBLE(M,D) means a double-
precision floating-point value: the M indicates the
maximum size of the value [in this case up to
9999999999999.99 {15 digits plus 1 point = 16}]
and the D indicates the number of digits after the
point [in this case 2]; PRIMARY KEY() specifies the
unique identity of each entry, achieved in this case
by combining the article key with the dealer key. This
table doesn't contain an extra 'primary key' column
as it's not necessary.
Use the search tool to find out about all the code in
the rest of the tutorial because, as I say, there are
very few detailed explanations for the uninitiated
from this point on and I wouldn't want to clutter up
the pages with superfluous comments.
Add your own comment.