电脑
MySqlWorkbench
打开MySqlWorkbench登录页面,输入密码,点击登录按钮
进入主页面,点击左上方的sql+按钮,如图所示:
创建表的时候创建普通索引sql语句结构为:create table table_name(col_name col_definition col_name col_definition ….col_name col_definition index index_name(col_name asc|desc));
举个例子:在library数据库中创建一个book表,以book_author字段来索引,sql语句如下:use library;create table book(isbn char(17),book_name varchar(50),book_author varchar(50),book_price decimal(3,1),press_id char(3),book_copy int,book_inventory char(50),index index_author (book_author))点击闪电标志的按钮,执行sql语句,显示执行成功。
查看普通索引,sql语句如下:show index from table_name;
查看刚刚创建的普通索引,sql语句如下:use library;show index from book;点击闪电标志的按钮,执行sql语句,显示执行成功。
在已经存在的表上创建普通索引,sql语句如下:create index index_name on table_name(col_name asc|desc)
举个例子:以isbn字段创建索引,sql语句如下:use library;create index index_isbn on book(isbn);点击闪电标志的按钮,执行sql语句,显示执行成功。
查看刚刚创建的普通索引,sql语句如下:use library;show index from book;点击闪电标志的按钮,执行sql语句,显示执行成功。
创建表索引有两种方法,一种是创建表的时候创建,一种是在已有的表上创建
记住创建和查看普通索引的关键词