打开phpstudy,打开Navicat for MySQL,进入要创建表格的数据库,点击上方“查询”按钮,“创建查询”,即可输入代码进行创建。
例:
create table class
( class_id int not null primary key, class varchar(255) not null, major varchar(255) not null , depart varchar(255) not null);create table stu_info( id int not null primary key, name varchar(90) not null , sex varchar(100) not null, age int, class varchar(20) not null, foreign key (class) references class(class_id));create table score( ids int auto_increment primary key, stu_id int not null, subject varchar(255) not null, score int not null );注意:
1.类型包含长度的在类型后面加括号,括号里面写长度2.上一列写完加逗号3.最后一列不要写逗号4.在每一条SQL语句写完之后要加分号5.如果有外键关系,先创建主表**自增长 auto_increment
**主键 primary key**外键 foreign key (列名) references 主表名(列名) **非空 not null创建数据库
create database test2; 删除数据库drop database test2;