mysql

1.创建数据据

create database mydb;

2.查看数据库

show create database mydb;

3.使用某个数据库

use 数据据名 -----use mydb

 

 

4.在控制台中插入中文数据需先  set character_set_client='gbk';

5.创建自增、带外键的表和如何插入数据

constraint stu_sid        foreign key (sid)           references student(sid),
constraint 外键名(随便取) foregin key (本表中对应那一列)references  参照表(列)

 

use stedent;
create table studCourse(
stuCourseId int auto_increment,
sid int ,
cid int ,
grade int not null,
primary key (stuCourseId),
constraint stu_sid foreign key (sid) references student(sid),
constraint stu_cid foreign key(cid) references course(cid)
);
插入数据到自增表,要表明插入的是哪几列,自增的那列可以不用声明
insert into studCourse(sid,cid,grade) values(20040001,11,90);
insert into studCourse(sid,cid,grade) values(20040001,21,19);
insert into studCourse(sid,cid,grade) values(20050003,21,45);
insert into studCourse(sid,cid,grade) values(20050004,41,99);
insert into studCourse(sid,cid,grade) values(20050006,11,39);

数据

学生表
create table student(
sid int,
sname varchar(45) not null,
ssex char(2) not null,
sdept varchar(10) not null,
sage int,
saddress varchar(45),
primary key (sid));

insert into student values(20040001,'林青霞','F','计算机系',22,'上海');
insert into student values(20040002,'刘德华','M','外语系',23,'南京');
insert into student values(20050003,'成龙','M','化学系',21,'山东');
insert into student values(20050004,'林可欣','F','计算机系',22,'北京');
insert into student values(20050005,'周华健','M','生物系',24,'山东');
insert into student values(20050006,'周润发','M','数学系',20,'湖北');

5.mysql 中 count(*)是计算返回的结果中有多少行

posted @ 2016-01-18 22:03  been  阅读(238)  评论(0编辑  收藏  举报