標籤:des 複製 new create int code column creat field
二、表操作
1、建立表
文法:( create table 表名( 欄位1 type 約束, 欄位2 type 約束, 欄位3 type 約束, . . . , . . . );)1、建立表格(表格中的欄位沒有任何約束)create table tb_student(id int, //沒有約束的表格建立name char(20),sex enum(‘男’,’女’));2、建立表格(添加了約束:unsigned 、primary key 、not null)create table tb_student(id int unsigned primary key, //有主鍵約束,加無符號約束,該處的主鍵約束可以放在最後,主鍵約束的作用:保證該記錄的唯一性。name char(20) not null, 主鍵是行的唯一識別碼,主鍵可以由一個欄位也可以由多個欄位組成,主鍵可以用來唯一確定表中的一條記錄。weight float(5,2)); 3、建立表格(表級約束添加在所有欄位後面)create table tb_student(id int unsigned,name char(20) not null, //非空約束是資料行層級條件約束,只能在欄位後聲明weight float(5,2),primary key (id) //將主鍵約束放在欄位聲明最後); 4、建立表格create table tb_student(id int unsigned auto_increment, auto_increment 是自增長,必須配合主鍵一起使用。name char(20) not null,weight float(5,2) not null,sex enum(‘男‘,‘女‘) not null,primary key(id),unique(name));
2、刪除表
drop table 表名;
3、修改表
1、複製表: create table tb2_name select * from tb_name; 2、建立暫存資料表: create temporary table tb_name; 3、重新命名表: alter table old_tb_name rename to new_tb_name;4、刪除表 drop table tb_name;5、顯示表結構 show columns from tb_name; desc tb_name;6、展示建立過程 show create table tb_name; 7、顯示索引相關資訊 show index from tb_name\g;8、alter 修改操作 //刪除欄位 alter table tb_name drop field_name; //添加欄位 alter table tb_name add field_name field_type constraint; //多欄位添加 alter table tb_name add (field1_name field1_type constraint,field2_name field2_type constraint ...); //在某個位置添加欄位 alter table tb_name add field_name field_type constraint after field_name; 9、change使用:alter table tb_student change name [to/as] student_name column_type constraint; (重新命名列也是一樣的,是建立了一個欄位替換了原來的欄位)10、為表添加描述資訊execute tb_student N‘MS_Description‘, ‘人員資訊表‘, N‘user‘, N‘dbo‘, N‘TABLE‘, N‘表名‘, NULL, NULL11、為欄位Username添加描述資訊execute tb_student N‘MS_Description‘, ‘姓名‘, N‘user‘, N‘dbo‘, N‘TABLE‘, N‘表名‘, N‘column‘, N‘Username‘12、為欄位Sex添加描述資訊execute tb_student N‘MS_Description‘, ‘性別‘, N‘user‘, N‘dbo‘, N‘TABLE‘, N‘表名‘, N‘column‘, N‘Sex‘13、更新表中列UserName的描述屬性:execute tb_student ‘MS_Description‘,‘新的姓名‘,‘user‘,dbo,‘TABLE‘,‘表名‘,‘column‘,‘UserName‘14、刪除表中列UserName的描述屬性:execute tb_student ‘MS_Description‘,‘user‘,dbo,‘TABLE‘,‘表名‘,‘column‘,‘Username‘ 【連結】mysql儲存過程詳解:http://blog.csdn.net/a460550542/article/details/20395225 【連結】http://blog.csdn.net/icanhaha/article/details/46965853 【連結】索引的優點和缺點 http://blog.csdn.net/qq247300948/article/details/23675843 【連結】MySQL中的各種引擎 http://blog.csdn.net/gaohuanjie/article/details/50944782
mysql-表操作