linux mysql 数据库 编程_linux下mysql数据库编程练习

mysql> use company;

Database changed

mysql> create table worker (nid INT UNIQUE,name VARCHAR(20), address VARCHAR(200), salary float, level int);

Query OK, 0 rows affected (0.18 sec)

mysql> insert worker values (100, 'tom','beijing',2000.0,0);

Query OK, 1 row affected (0.14 sec)

mysql> insert worker values (101, 'jim','shanghai',2000.0,1);

Query OK, 1 row affected (0.01 sec)

mysql> insert worker values (102, 'mali','shanghai',3000.0,2);

Query OK, 1 row affected (0.00 sec)

mysql> select * from worker;

+------+------+----------+--------+-------+

| nid  | name | address  | salary | level |

+------+------+----------+--------+-------+

|  100 | tom  | beijing  |   2000 |     0 |

|  101 | jim  | shanghai |   2000 |     1 |

|  102 | mali | shanghai |   3000 |     2 |

+------+------+----------+--------+-------+

3 rows in set (0.00 sec)

mysql> delete from woker where nid = 100;

ERROR 1146 (42S02): Table 'company.woker' doesn't exist

mysql> delete from worker where nid = 100;

Query OK, 1 row affected (0.07 sec)

mysql> select * from worker;

+------+------+----------+--------+-------+

| nid  | name | address  | salary | level |

+------+------+----------+--------+-------+

|  101 | jim  | shanghai |   2000 |     1 |

|  102 | mali | shanghai |   3000 |     2 |

+------+------+----------+--------+-------+

2 rows in set (0.00 sec)

mysql> update worker set level = 2, salary=3000.0 where nid=101;

Query OK, 1 row affected (0.12 sec)

Rows matched: 1  Changed: 1  Warnings: 0

proud.gif

laugh.gif

mysql> select * from worker;

+------+------+----------+--------+-------+

| nid  | name | address  | salary | level |

+------+------+----------+--------+-------+

|  101 | jim  | shanghai |   3000 |     2 |

|  102 | mali | shanghai |   3000 |     2 |

+------+------+----------+--------+-------+

2 rows in set (0.00 sec)

mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | ZHANG              | | company            | | mysql              | | performance_schema | | test               | +--------------------+ 6 rows in set (0.00 sec) mysql> drop ZHANG     -> ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ZHANG' at line 1 mysql> DROP DATABASE ZHANG; Query OK, 0 rows affected (0.03 sec) mysql> CREATE DATABASE linuxcast; Query OK, 1 row affected (0.00 sec) mysql> USE linuxcast; Database changed mysql> CREATE TABLE lC_course(id int, course_name varchar(100),course_length int(10),teacher varchar(50),caategory varchar(100)); Query OK, 0 rows affected (0.15 sec) mysql>  mysql>  mysql> show Tables; +---------------------+ | Tables_in_linuxcast | +---------------------+ | lC_course           | +---------------------+ 1 row in set (0.00 sec) mysql> DESCRIBE lc_course; ERROR 1146 (42S02): Table 'linuxcast.lc_course' doesn't exist mysql> DESCRIBE lc_course; ERROR 1146 (42S02): Table 'linuxcast.lc_course' doesn't exist mysql> DESCRIBE lC_course; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(50)  | YES  |     | NULL    |       | | caategory     | varchar(100) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 5 rows in set (0.10 sec) mysql> DESC lC_course; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(50)  | YES  |     | NULL    |       | | caategory     | varchar(100) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec) mysql> show tables; +---------------------+ | Tables_in_linuxcast | +---------------------+ | lC_course           | +---------------------+ 1 row in set (0.00 sec) mysql> ALTER TABLE lC_course REMALE course; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REMALE course' at line 1 mysql> ALTER TABLE lC_course RENAME course; Query OK, 0 rows affected (0.16 sec) mysql> show tabels; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tabels' at line 1 mysql> show tables; +---------------------+ | Tables_in_linuxcast | +---------------------+ | course              | +---------------------+ 1 row in set (0.00 sec) mysql> decs course; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'decs course' at line 1 mysql> DESC course; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(50)  | YES  |     | NULL    |       | | caategory     | varchar(100) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 5 rows in set (0.03 sec) mysql> ALTER TABLE course ADD link varchar(200); Query OK, 0 rows affected (0.28 sec) Records: 0  Duplicates: 0  Warnings: 0 mysql> DESC course; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(50)  | YES  |     | NULL    |       | | caategory     | varchar(100) | YES  |     | NULL    |       | | link          | varchar(200) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 6 rows in set (0.00 sec) mysql> ALTER TABLE course DROP COLUMN link; Query OK, 0 rows affected (0.10 sec) Records: 0  Duplicates: 0  Warnings: 0 mysql> DESC course; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(50)  | YES  |     | NULL    |       | | caategory     | varchar(100) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 5 rows in set (0.01 sec) mysql>  mysql> ALTER TABLE course MODIFY teacher varchar(100); Query OK, 0 rows affected (0.09 sec) Records: 0  Duplicates: 0  Warnings: 0 mysql> ALTER TABLE course CHANGE COLUMN caategory tategory varchar(100); Query OK, 0 rows affected (0.10 sec) Records: 0  Duplicates: 0  Warnings: 0 mysql> DESC course     -> ; +---------------+--------------+------+-----+---------+-------+ | Field         | Type         | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+-------+ | id            | int(11)      | YES  |     | NULL    |       | | course_name   | varchar(100) | YES  |     | NULL    |       | | course_length | int(10)      | YES  |     | NULL    |       | | teacher       | varchar(100) | YES  |     | NULL    |       | | tategory      | varchar(100) | YES  |     | NULL    |       | +---------------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值