284354749 发表于 2018-10-10 07:46:36

mysql建表插入数据

  /*create user table*/
  create table user(

  /*set the>  id int primary key auto_increment ,
  name char(10) not null,
  /*this check sex in male or female ,don't use not null here*/
  sex char(6) check(sex in ('male','female')),
  age int not null
  );
  /*this Sql script insert one row into user table*/
  insert into user (name,sex,age) values("wanggangdan",'male',18);create table Student1(
  Sno char(8) primary key not null,
  Sname varchar(10) not null,
  Sex char(2) check(Sex in ('男','女')),
  Age int not null,
  Phonenumber char(12) unique,
  Sdept varchar(20) not null
  );
  create table Course(
  Cno char(10) primary keynot null,
  Cname varchar(20) not null,
  Total_perior tinyint,
  Week_perior tinyint,
  credit tinyint not null,
  Pcno char(10)
  );
  create table SC(
  Sno char(8) not null,
  Cno char(10) not null,
  Grade tinyint,
  /*set Sno & Cno as the primary key*/
  primary key(Sno,Cno),
  /*set the refereneces of Sno & Cno*/
  foreign key(Sno) references Student1(Sno),
  foreign key(Cno) references Course(Cno)
  );

页: [1]
查看完整版本: mysql建表插入数据