试验训练1在MySQL中创建数据库和表作业.docx

上传人:scccc 文档编号:13073177 上传时间:2021-12-13 格式:DOCX 页数:5 大小:35.58KB
返回 下载 相关 举报
试验训练1在MySQL中创建数据库和表作业.docx_第1页
第1页 / 共5页
试验训练1在MySQL中创建数据库和表作业.docx_第2页
第2页 / 共5页
试验训练1在MySQL中创建数据库和表作业.docx_第3页
第3页 / 共5页
试验训练1在MySQL中创建数据库和表作业.docx_第4页
第4页 / 共5页
试验训练1在MySQL中创建数据库和表作业.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《试验训练1在MySQL中创建数据库和表作业.docx》由会员分享,可在线阅读,更多相关《试验训练1在MySQL中创建数据库和表作业.docx(5页珍藏版)》请在三一文库上搜索。

1、实验训练1在MySQL中创建数据库和表作业步骤:1、使用show语句找出在服务器上当前存在什么数据库:mysql>show databases;ny零shoudatabases:+!DatabaseII+!infornation_schema!:咐sql:!pe i*f orman cehe ma!Isakila!Ismsi;MOi'ldI+5 rows in set <0_00 sec>2、创建一个数据库test:mysql>create database test;9M】create dtahAse test;uerv OK# 1 row affected

2、<0.03 sec>3、选择你所创建的数据库:mysql>use test;iysql> use test: atabase changed4创建一个数据表:首先查看刚才创建的数据库中存在什么表:mysql>show tables;(说明刚才创建的数据库中还没有数据库表) 接着我们创建一个关于 students的数据表:包括学生的学号(id),姓 名(name),性别(sex),年龄(age)。mysql>create table students(id int unsigned not null auto_increment primary key,nam

3、e char(8) not null,sex char(4) not null,age tinyint unsigned not null,);iysql> create table students (id int unsigned not null autu_inccement pi'inari; hey char<8> not null,sex chat*<4> not nullFasre tinyint unsisfned not r»ull>;juer QK, 0 rows affected <0.39 sec>命军释

4、: 以 "id int unsigned not null auto_increment primary key"行进行介绍:"id"为列的名称;"int"指定该列的类型为int(取值范围为-8388608到8388607),在后 面我们又用"unsigned"加以修饰,表示该类型为无符号型,此时该 列的取值范围为 0到16777215;"not null"说明该列的值不能为空,必须要填,如果不指定该属性,默 认可为空;"auto_increment"需在整数列中使用,其作用

5、是在插入数据时若该列 为NULL, MySQL将白动产生一个比现存值更大的唯一标识符值。在每张表中仅能有一个这样的值且所在列必须为索引列。"primary key"表示该列是表的主键,本列的值必须唯一,MySQL将 白动索引该列。下面的char(8)表示存储的字符长度为8, tinyint的取值范围为-127 到128, default属性指定当该列值为空时的默认值。创建一个表后,用show tables显示数据库中有哪些表: mysql>show tables;show tables;I students+pol? in set <0.00 sec5、显示表结

6、构:mysql>describe students;iysql> describe students f:Field : TypeT1:Null :rT"噌! Key I Default !Li , I Extraid name sex age'int<10>unsigned'NO:char<8>!HO:char<4>;NO:tinyint(3>unsigned :NOPHI ! HULL ! NULL :NULL :NULLauto.increment 'rous in set <6-04 sec6

7、、在表中添加记录:首先用select命令来查看表中的数据:mysql>select*from students;iysql> select*ft'om students: inptj/ cet <0-00 sec>(说明刚才创建的数据库表中还没有任何记录)接着加入一条新纪录:mysql>insert into students value(01 'Tom', F, 18);9sql> insert into students value<,l,JTonF,JF,18,>; uepy OK, 1 row affected &

8、lt;0_07 sec>再用select命令来查看表中的数据的变化:mysql>select*from students;7、用文本方式将数据装入一个数据库表:创建一个文本文件“ student.sql',每行包括一个记录,用 TAB键把 值分开,并且以在create table语句中列出的次序,例如:02 Tony F 1803 Amy M 1804 Lisa M 18将文本文件“ student.sqf装载到students表中:mysql>load data local infile” estudent.sql into table students;load data locl inf ileMe - Wstudentstable studien t£luery OK- 0 affected <0.00 sec> iecords: 3 Deleted; 0 Skipped: 3 Warnings: 0再使用select命令来查看表中的数据的变化:mysql>select*from students;i</sql> select « £ron students;rows in set <0.00 sec>

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1