1.顯示資料庫列表:
show databases; -- 用於可檢視你當前一共有多少個資料庫!
2.使其成為當前運算元據庫
use mysql; -- 開啟資料庫. 選擇進入你想進入的資料庫
show tables; -- 顯示mysql資料庫中的資料表. 顯示的是你輸入的資料庫當中的所有表
3.顯示資料表的表結構:
descrip student; -- 用於顯示student這個表的結構
4.建立資料庫,建表
create database mydatabase; -- 建立乙個資料庫
use mydatabase; -- 開啟這個資料庫
create table 表名; -- 建立乙個表
5.刪除資料庫,冊除表
drop database 資料庫名;
drop table 表名;
6.查詢
select * from 表名;
7.增加字段:
alter table 表名 add column 《欄位名》《字段選項》
8.修改字段:
alter table 表名 change 《舊欄位名》 《新欄位名》 《選項》 -- 選項是指新字段的型別 是否為空
9.刪除字段:
alter table 表名 drop column 《欄位名》
10總結一下上面的操作
create database office;
use office;
create table `newtable` (
`member_no` char(5) not null ,
`name` char(10) null ,
`birthday` date null ,
`exam_score` tinyint(10) null ,
primary key (`member_no`)
);修改資料庫表:
要求: 在birthday這後增加乙個為height的字段,資料型別為tinyint.
將字段exam_score 改名為scores,資料型別不變
alter table personal
add column height tinyint after birthday,
change column exam_score scores tinyint;
給表中插入資料:
update personal set scores=95 where name='netseek';
根據分數查詢
select scores from personal where name='netseek';
刪除表名字為'gogo'所有的資訊中的的:
delete from personal where name='gogo';
冊除資料庫中的表:
drop table if exists personal;
--檢視表結構
exec sp_help 'tabname' desc tabname
--更改表名
alter table tabname rename newtabname
--更改字段型別
alter table modify id bigint
--新增字段
alter table t_stuinfo add sname varchar(200) null
--刪除字段
alter table t_stuinfo drop sid
--新增主鍵/外來鍵
alter table table_name add constraint pk_name primary key(列名);
alter table subtabname add constraint fk_subtabname_tabname
foreign key subtabname(fid) references tabname(id);
--刪除主鍵/外來鍵
alter table tabname drop primary key pk_tabname
alter table subtabname drop foreign key fk_subtabname_tabname
--刪除約束
alter table tabname drop constraint constaintname
--刪除表
drop table if exists tabname,subtabname;
--檢視
desc view_name;
show create view view_name;
Qt中常用的資料庫操作
簡述 常用的資料庫操作主要有查詢 插入 刪除等 qsqldatabase建立連線資料庫例項,乙個qsqldatabase的例項代表乙個資料庫的連線。qt 提供了對不同資料庫的驅動支援 driver type description qdb2 ibm db2 qibase borland interb...
自己常用的資料庫操作語句
經常運算元據庫,很多語句都是現用現查,比較麻煩,還是統一整理個地方,記錄下來,以備後用。一 安全性方面 1 建立架構 同時授權給指定使用者,注意此使用者必須是資料庫中對映的使用者名稱,而不是登入名 alter schema schema name authorization user name 2 ...
資料庫中常用的對字段的操作
1.增加字段 alter table 表名 add 欄位名稱 字段型別alter table course add tid int 在課程表中增加教師編號tid欄位alter table 表名 add 欄位名稱 字段型別,欄位名稱 字段型別.增加多個字段2.修改字段 1 修改欄位的名稱 alter ...