当前位置:沸点梦工场 > 网页编程 > Mysql教程 > 浏览文章

MYsql数据库入门教程

59HOT收集整理 2008年06月13日 【字体:

  6、创建一个表

  create table student

  (

  name varchar(20) not null,

  sex enum('f','m') not null,

  student_id int unsigned not null auto_increment primary key

  )

  create table absence

  (

  student_id int unsigned not null,

  date date not null,

  primary key (student_id,date)

  )

  7、增加新记录

  mysql>insert into student values('kyle','m',null);

  insert into table_name values(...),(...);

  insert into member(last_name,fist_name) values('stain','kelly');

  insert into student(name,sex) values('abbly','f'),('lily','m');

  insert into member set last_name='stein',fist_name='waldo';

  将记录装到表中的另一种方法是直接从文件读取数据值。可以用LOAD DATA 语句或用mysqlimport 实用程序来装入记录。LOAD DATA 语句起批量装载程序的作用,它从一个文件中读取数据。

  load data local infile "member.txt" into table member;

  mysqlimport..lacal samp_db member.txt

  8、检索信息

  select * from president

  select birth_date from president where last_name = "esihower";

  为了编写SELECT 语句,只需指定需要检索什么,然后再选择某些子句即可。刚才给出的子句“ FROM”、“WHERE”是最常用的,还有一些其他的子句,如GROUP BY、ORDER BY和LIMIT 等。FROM 子句一般都要给出,但是如果不从表中选择数据,也可不给出。例如,下列查询只显示某些可以直接计算而不必引用任何表的表达式的值,因此不需要用FROM 子句:

  mysql>select 2+2,"hello,world",version();

  如果只选择某列,则:

  select name from student;

  select name, sex, student_id from student;

上一页
本文共 2 页,第  [1]  [2]  页