今日使用学习MySql指令

来源:互联网 发布:plc编程小游戏 编辑:程序博客网 时间:2024/05/21 15:44

查看所有的数据库

show databases;

创建数据库

create databaseName(数据库名);

切换数据库

use databaseName(数据库名);

判断表是否存在,存在删除,然后创建表

drop table if exists tableName(表名);

create table tableName(表名)   (

id int primary key auto_increment, -- primary key(将此列设为主键列) auto_increment(将此列设为自增列)

testId not null,

name varchar(20) not null,-- not null(添加非空约束)

sex bit  not null default true, -- default true(添加默认约束)

index(testId),-- 创建普通索引

);

添加约束

alter table tableName(表名)  add constraint (约束名) foreign key (id(需添加约束的外键列)) references testTableName(testId) (主键表表名(主键表主键));

修改某一列属性

alter table tableName(表名) change id(要修改的列名) id(修改后的列名) int primary key(修改后的属性);

添加索引

create index  index_name ontable(column(length));




0 0