資料庫-單表結構-建表語句

wu33169發表於2024-08-28

1.mysql -uroot -p
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2.show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| dcs46 |
| mysql |
| test |
+--------------------+

3.use test;
mysql> use test;
Database changed

5.select database();

6.desc test;

7.mysql> create table student(class int(20),chinese int(20),english int(20),math int(20),name varchar(30),age int(
10),sid int(20) not null primary key auto_increment);

mysql> desc student;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| class | int(20) | YES | | NULL | |
| chinese | int(20) | YES | | NULL | |
| english | int(20) | YES | | NULL | |
| math | int(20) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| age | int(10) | YES | | NULL | |
| sid | int(20) | NO | PRI | NULL | auto_increment |
+---------+-------------+------+-----+---------+----------------+

mysql> insert into student(class,chinese,english,math,name,age,sid)values(1833,86,90,40,"zhangsan",21,1),(1832,55,86,66,"lisi",23,2),(1833,93,57,98,"zhaoliu",33,3),(1832,84,90,88,"wangwu",24,4),(1833,93,57,22,"lijiu",25,5),(1832,84,98,77,"liuli",27,7),(1833,48,58,88,"wangsan",19,9),(1833,87,60,65,"wangan",19,10),(1832,80,76,88,"wangping",17,11),(1833,null,79,88,"wanghui",20,12);

mysql> select * from student;
+-------+---------+---------+------+----------+------+-----+
| class | chinese | english | math | name | age | sid |
+-------+---------+---------+------+----------+------+-----+
| 1833 | 86 | 90 | 40 | zhangsan | 21 | 1 |
| 1832 | 55 | 86 | 66 | lisi | 23 | 2 |
| 1833 | 93 | 57 | 98 | zhaoliu | 33 | 3 |
| 1832 | 84 | 90 | 88 | wangwu | 24 | 4 |
| 1833 | 93 | 57 | 22 | lijiu | 25 | 5 |
| 1832 | 84 | 98 | 77 | liuli | 27 | 7 |
| 1833 | 48 | 58 | 88 | wangsan | 19 | 9 |
| 1833 | 87 | 60 | 65 | wangan | 19 | 10 |
| 1832 | 80 | 76 | 88 | wangping | 17 | 11 |
| 1833 | NULL | 79 | 88 | wanghui | 20 | 12 |
+-------+---------+---------+------+----------+------+-----+
10 rows in set (0.00 sec)

mysql> select * from student where class=1832; 1、查詢1832班的成績資訊
+-------+---------+---------+------+----------+------+-----+
| class | chinese | english | math | name | age | sid |
+-------+---------+---------+------+----------+------+-----+
| 1832 | 55 | 86 | 66 | lisi | 23 | 2 |
| 1832 | 84 | 90 | 88 | wangwu | 24 | 4 |
| 1832 | 84 | 98 | 77 | liuli | 27 | 7 |
| 1832 | 80 | 76 | 88 | wangping | 17 | 11 |
+-------+---------+---------+------+----------+------+-----+
4 rows in set (0.00 sec)

mysql> select * from student limit 4,6;
+-------+---------+---------+------+----------+------+-----+
| class | chinese | english | math | name | age | sid |
+-------+---------+---------+------+----------+------+-----+
| 1833 | 93 | 57 | 22 | lijiu | 25 | 5 |
| 1832 | 84 | 98 | 77 | liuli | 27 | 7 |
| 1833 | 48 | 58 | 88 | wangsan | 19 | 9 |
| 1833 | 87 | 60 | 65 | wangan | 19 | 10 |
| 1832 | 80 | 76 | 88 | wangping | 17 | 11 |
| 1833 | NULL | 79 | 88 | wanghui | 20 | 12 |
+-------+---------+---------+------+----------+------+-----+
6 rows in set (0.00 sec)

相關文章