常用sql語句整理

2021-10-01 12:10:14 字數 673 閱讀 1503

查詢

無條件查詢  select * from table_name

條件查詢 select * from table_name where 條件

排序查詢 select col1,col2,...from table_name where 條件 .. order by 列名 desc/asc 

模糊查詢 select * from student where s_name like '張%'

多表查詢(兩表)  select c.id, u.user_id from company as c,user_company_rel as u where c.id = u.company_id and c.deleted = 0

刪除

刪除一條資料 delete from 表名稱 where 列名稱 = 值

刪除整表的資料 truncate table tablename(表名)

刪除整表後,id 從『1』開始  truncate table tablename(表名)

更新

更新某行中的某列 update 表名set 列名= '值' where 條件

更新某行中的多個列 update 表名set 列名1= '值', 列名2= '值' where 條件

常用sql語句整理

a 判斷資料庫是否存在 if exists select from sys.databases where name 庫名 刪除資料庫 drop database 庫名b 判斷要建立的表名是否存在 if exists select from dbo.sysobjects where id objec...

常用SQL語句整理

檢視資料庫 show databases 選擇資料庫 use database name 表定義資訊 describe table name 插入資料 insert into table name filed 1 field n values value 1 value n eg insert in...

常用sql語句整理

1.資料庫層面 建立資料庫 create database database name 刪除資料庫 drop database database name 2.表建立新錶 create table tablename col1 type1 not null primary key col2 type...