LINUX.ORG.RU

Вопрос по mysql


0

0

mysql> DESCRIBE USER;
+---------------+-------------+------+-----+---------------------+--------------
--+
| Field         | Type        | Null | Key | Default             | Extra          |
+---------------+-------------+------+-----+---------------------+--------------
--+
| U_ID          | int(11)     |      | PRI | NULL                | auto_increment |
| U_NAME        | varchar(64) |      | UNI |                     |                |
| U_PASSWORD    | varchar(64) | YES  |     | NULL                |                |
| U_STATUS      | int(11)     |      |     | 0                   |                |
| U_TIME        | datetime    |      |     | 0000-00-00 00:00:00 |                |
| U_INFO        | blob        | YES  |     | NULL                |                |
| U_SKIN        | varchar(16) |      |     |                     |                |
| U_COLORSCHEME | varchar(16) |      |     |                     |                |
+---------------+-------------+------+-----+---------------------+--------------
--+
8 rows in set (0.00 sec)

mysql> INSERT INTO USER (U_ID, U_NAME) VALUES(32, 'user 32');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO USER (U_ID, U_NAME) VALUES(93, 'user 93');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO USER (U_ID, U_NAME) VALUES(1, 'user 1');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO USER (U_ID, U_NAME) VALUES(0, 'user 0');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM USER;
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
| U_ID | U_NAME  | U_PASSWORD | U_STATUS | U_TIME              | U_INFO | U_SKIN | U_COLORSCHEME |
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
|   32 | user 32 | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|   93 | user 93 | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|    1 | user 1  | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|   94 | user 0  | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
4 rows in set (0.00 sec)

mysql> UPDATE USER SET U_ID = 0 WHERE U_ID = 94;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT * FROM USER;
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
| U_ID | U_NAME  | U_PASSWORD | U_STATUS | U_TIME              | U_INFO | U_SKIN | U_COLORSCHEME |
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
|   32 | user 32 | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|   93 | user 93 | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|    1 | user 1  | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
|    0 | user 0  | NULL       |        0 | 0000-00-00 00:00:00 | NULL   |        |               |
+------+---------+------------+----------+---------------------+--------+-------
-+---------------+
4 rows in set (0.00 sec)

Т.е. когда мы пытаемся INSERT пользователя с ключевым полем 0, то не работает, а с помощью UPDATE работает.
Почему?
★★★★★

Re: Вопрос по mysql

0 для автоинкремента

theserg ★★★ ()

Re: Вопрос по mysql

читай маны про auto_increment:
http://dev.mysql.com/doc/refman/4.1/en/create-table.html
 An integer column can have the additional attribute AUTO_INCREMENT. When you insert a value of NULL (recommended) or 0 into an indexed AUTO_INCREMENT column, the column is set to the next sequence value. Typically this is value+1, where value is the largest value for the column currently in the table. AUTO_INCREMENT sequences begin with 1. Such a column must be defined as one of the integer types as described in Section 11.1.1, “Overview of Numeric Types”. (The value 1.0 is not an integer.) See Section 18.2.3.35, “mysql_insert_id()”.

As of MySQL 4.1.1, specifying the NO_AUTO_VALUE_ON_ZERO flag for the --sql-mode server option or the sql_mode system variable allows you to store 0 in AUTO_INCREMENT columns as 0 without generating a new sequence value. See Section 5.2.1, “mysqld Command-Line Options”.

anonymous ()
Ответ на: Re: Вопрос по mysql от anonymous

Re: Вопрос по mysql

Понятно, спасибо за разъяснение. К сожалению запускать mysql я не могу, ну ладно.

Legioner ★★★★★ ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.