SQL資料庫學習之路(五)

2021-09-19 21:27:09 字數 1966 閱讀 3827

select *from classid as id  --選擇classid 表,起別名為id(一般因為原來名字太長所以起短一點的別名)

select classname as 姓名 from classid id    --選擇classid表中的classname列,結果視窗只會顯示該列.可以為該列起中文別名。

top n 列名:表示檢視前n行

select top 1 * from gg   --查詢gg表第一行的資料

top n percent 列名:表示檢視前百分之幾的資料。

select top 50 percent  * from gg   --查詢gg表前50%的資料

select *from gg order by id desc  --將gg表由id列由大到小排序

select distinct id from gg   --消除gg表中id重複的行

對行進行篩選,返回bool型別的值。

比較運算子:=,>,>=,

between...and ...表示在一定的範圍之內。                   in表示在乙個非連續的範圍內。

邏輯運算子:and   or   not

select *from gg where id=4  --查詢gg表中id列=4的行

select *from gg where id between 2 and 3   --查詢gg表中id為2和3之間的行

select *from gg where id in(1,5)   --查詢gg表中id為1或5的行

select *from gg where not id=3    --查詢gg表中id不為3的行

運算子包括:like% (表示0到多個)_(表示乙個任意字元)^                       

% 與_寫在中表示本身的意思

在中表示乙個連續的範圍可以使用 -

^寫在內部的開頭,表示不使用內部的任何字元

null的判斷:使用is null或者is not null

例子:select *from gg where name like '%青%'   ---模糊查詢,名字裡面包含青的

select *from gg where name like '_虎'   ---模糊查詢,名字裡面第二個字是虎的

update gg set name =null where id=2    --將id為2的名字設定為空

SQL資料庫學習之路(三)

一.表資料的操作 1.簡單查詢 select from 表名 2.增加資料 insert into 表名 列名 values 值 要求值的列名與值要位置對應 如果所有都插入值,可以省略列名部分 insert textinfo name,pwd values 黑子 ba65d6181092fdb8e9...

SQL資料庫學習之路(二)

一 1.約束 實現資料的有效性檢查 主鍵 保證值是唯一的 2.非空 輸入的資料不允許為空 3.唯一 存入的資料不能重複 4.預設 自己不給資料新增值,值會預設新增 5.檢查 給值乙個選定的範圍 6.外來鍵 對關係的有效性進行檢查,有關係才有外來鍵 二 指令碼運算元據庫 1.不區分大小寫,字串使用單引...

資料庫學習之路

資料庫入門 什麼是資料庫 資料庫的工具,如何使用 1 資料庫 2 流行資料庫 mysql sqlserver oracle 3 如何學 資料庫操作 設計資料庫 設定資料之間的關係 建立模型 資料庫操作的相關命令 資料庫sql 語句學習 4 連線資料庫 用工具連線資料庫 資料庫通常不在本地 5 資料庫...