Mysql表操作 基本操作

2021-10-04 06:39:48 字數 1576 閱讀 5372

create table t5 (

id int,

name varchar ( 10 ));

show create table t5;

create table t8 (

id int not null,

name varchar ( 10 )

) engine myisam default charset = utf8;

drop table if exists t7;

create table t9(id int,tid int unique);//不可以重複的

insert into t9 values (11,11),(22,22),(33,33);

insert into t9 values (11,11);//唯一性約束不可以重複

#自增長 主鍵

create table t10 (

id int primary key auto_increment,

name varchar ( 10 ));

desc t10;

insert into t10

values

( 1, 'dasd' );

insert into t10 ( name )

values

( 'dasd' );

alter table t6 rename t11; //修改表名

alter table t11 modify name varchar(30); //修改表字段型別

alter table t11 change name uname varchar(20);//修改表的欄位名稱及型別

alter table t11 add location varchar(50); //在末尾增加乙個字段

alter table t11 add age int not null after uname;//指定在哪個字段後面新增字段

alter table t11 add collno int first;//第一列新增字段

alter table t11 drop collno; //刪除指定字段

alter table t11 modify location varchar(30) after uname;//修改表中的字段排列順序

alter table t11 engine innodb;//修改儲存資料引擎

desc t11;

insert into t11 values(2,'ds2a','dsa',20);

insert into t11 (id,uname,location,age) select id,uname,location,age from t11;//子查詢插入資料

update t11 set uname='12312' where id=2;//指定修改

delete from t11 where id=1; //刪除資料

//開啟事物

begin

insert into t11 values (3,'sfds',30);

rollback;

commit;

mysql表基本操作

alter table empleey drop name2 alter table empleey add name2 varchar 100 alter table empleey modify column name varchar 2000 alter table empleey chang...

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...