資料庫語句 表操作

2021-09-29 05:26:42 字數 1505 閱讀 4363

1.檢視表結構

desc 表名
2.建立表結構的語法

create table table_name(欄位名 資料型別 可選的約束條件);
demo:建立班級和學生表

create table classes(

id int unsigned auto_increment primary key not null,

name varchar(10)

);

create table students(

id int unsigned primary key auto_increment not null,

name varchar(20) default '',

age tinyint unsigned default 0,

height decimal(5,2),

gender enum('男','女','人妖','保密'),

cls_id int unsigned default 0

)

3.修改表–新增字段

alter table 表名 add 列名 型別

demo:alter table students add birthday datetime;

4.修改表–修改字段–重新命名版

alert table 表名 change 原名 新名 型別及約束
demo:alter table syudents change birthday birth datetime not null;

5.修改表–修改字段–不重新命名

alter table 表名 modify 列名 型別及約束
demo :alter table students modify birth date nout noll;

6.刪除表–刪除字段

alter table 表名 drop 列名
demo :alter table students drop birthday;

7.刪除表

drop table 表名
demo:drop table students;

8.檢視表的建立語句–詳細過程

show create table 表名
demo :show create tabele students;

資料庫操作表資料基本語句

insert into 語句用於向表中插入新記錄。sql insert into語法 insert into 語句可以有兩種編寫形式。第一種形式無需指定要插入資料的列名,只需提供被插入的值即可 insert into table name 表名 values value1 取值 value2,val...

資料庫與表的操作語句

例 create database if not exists intheima use itheima create table if not exists student id int unsigned primary key auto increment comment 學號 name var...

資料庫操作語句

mysql分頁limit用法 limit後的第乙個引數是輸出記錄的初始位置,第二個引數偏移量。如 select from tables limit 10,3 返回的就是11到13,3條資料。如果只給定乙個引數,它表示返回最大的記錄行數目 select from table limit 5 檢索前 5...