談談資料庫sql語句

2021-08-07 19:54:15 字數 1422 閱讀 3195

1、sql(structured query language)

2、建立表:create table 表名(column1 datatype (length) ,column2 datatype (length),...)

3、插入語句:insert into table(field1,field2) values(value1,value2)

4、更新語句:update table set field1=value1,field2=value2 where field3=value3(set後多個條件用逗號 而不是and,where後多個條件用and)

5、刪除語句:delete from table where field=value

6、查詢語句:select * from table查詢表內所有內容(無條件查詢)

select field1 from table where field2=value1(有條件查詢)

select field1,field2 from table(多個字段查詢)

select field1 as field3,field2 as field4 from table(給字段設定別名,as可以省略)

select distinct field1 as field2 from table(distinct 選擇不重複的結果)

select field1 from table where field2<>10(篩選字段小於10的結果)(<>不等於,!=不等於)

(any, some 任何乙個)(all所有的)

7、模糊查詢:

select * from table where f like 'g%'(g開頭的所有結果都可以查出)(like不和%和_一起使用,就相當於=)

select * from table where f like '%g'(g結尾的所有結果都可以查出)

select * from table where field like 'g_'(_代表乙個字元)

select * from table where field like '\%%'(\%代表將%轉義)

select * from table where field like 'a%%' escape 'a'(a相當於\)

8、 邏輯符合條件關鍵字:not 、or 、and

select * from table where filed1=value1 or field1=value2與select * from table where field1 in(2,3)相同

9、對查詢結果進行排序

select * from table where field in(2,3) order by field desc(降序)

select * from table where field in(2,3) order by field asc(公升序)

資料庫 SQL語句

在sql語言中,我們可以通過create database去建立資料庫,語法格式如下所示 create database 資料庫名 就比如我們可以建立乙個學校資料庫 create database schooldb 建立表的操作 create table 表名稱 列名稱1 資料型別,列名稱2 資料型...

談談資料庫更新 Update語句 查詢

談談資料庫更新 update語句 查詢 今天有人在群上問了關於資料庫更新的問題,在此,我將資料庫更新的問題給總結一下 說白了,資料庫更新就一種方法update,其標準格式 update 表名 set 字段 值 where 條件 不過根據資料的 不同,還是有所區別的 1.從外部輸入 這種比較簡單 例 ...

SQL語句建立資料庫

1.create database dataname 這是建立資料庫最簡單的方法 資料庫的各個屬性都是預設 如資料庫檔案與日誌檔案儲存目錄 資料庫大小等 下面介紹下常用決定資料庫屬性的子句 on 簡單理解為定義儲存資料庫檔案的位置,看下面 filename 資料庫的邏輯別名 size 資料庫初始大小...