查詢所有的資料庫:show databases;
建立資料庫:create database 資料庫名;
刪除資料庫:drop database 資料庫名;
sql語句的表操作;
選中操做的資料庫:use 資料庫名;
檢視資料庫中的所有表:show tables;
建立表:create table 表名(
id int(4);
name varchar(3);
age int(3)
注意:int(4)和int()的區別,乙個是指定長度是4,第二個使用預設值11
檢視表結構:
1)sql格式:show create table 表名;
2)**格式:desc表名;
構建相同表結構:
create table 複製的表 like 被複製的表名;
修改表:
1)新增字段:add
alter table 表名 add 欄位名 字段型別;
同時新增兩個以上字段:alter table 表名 add 欄位名 字段型別, add 欄位名 字段型別,...;
2)修改字段型別:modify
alter table 表名 modify 欄位名 新的字段型別;
3)修改欄位名稱:change
alter table 表名 change 欄位名 新的欄位名 字段型別;
4)刪除字段:drop
alter table 表名 drop aa,drop bb;
5)修改表名:rename
alter table 表名rename 新錶名;
練習:1. 在mydb中建立乙個員工表
字段 屬性
id 整型
name 字串(長度為10)
*** 字串(長度為2)
birthday 日期型(date)
字串(長度為10)
remark 字串(長度為50)
分別以**方式和sql方式顯示表的結構
2.修改表練習
1 在員工表基礎上增加salary(double型別)列
2 修改name的長度為20
3 刪除email列
4 列名remark修改為resume
sql語句建立表
create table search custom mall id int 11 not null primary keyauto increment,uid int 11 not null name varchar 150 not null search mall id int 11 not n...
sql語句之表增刪改操作
1 插入資料 insert into 表名 列名,列名,列名 values 值,值,值 例 向emp表中插入一條資料 insert into emp id,name,values 1,劉備 男 2 修改資料 修改表中所有的記錄 update 表名 set 列名 值 符合修改條件的記錄 update ...
mysql建立表sql語句
直接給出sql語句 drop table if exists test table name create table test table name id int 11 not null auto increment comment 主鍵 del int 1 default 1 comment 0...