1. 程式人生 > 其它 >C++基礎-結構體偽函式與多執行緒(void operator()(int))

C++基礎-結構體偽函式與多執行緒(void operator()(int))

SQL

User表
id pwd name
0 123 gan
1 123 gan
3 12 peng
book表
Bname aUtherId catagory
數學 1 工具
語文 0 文學
英語 2 語言

select從資料庫中提取資料

select * from user

select user.id from user

distinct關鍵字 選取唯一不同的值
select distinct user.name from user

where子句
select * from user where user.id=1
where子句中的運算子
= 等於
<>/!= 不等於
> 大於
< 小於
>= 大於等於
<= 小於等於
betweent and 在某個範圍內
like 搜尋某種模式
in 指定針對某個列的多可能值

and 和 or 運算子
如果第一個條件和第二個條件都成立,則 AND 運算子顯示一條記錄。
如果第一個條件和第二個條件中只要有一個成立,則 OR 運算子顯示一條記錄。
select * from user where uid=1 and name='gan'
select * from user where uid=1 or name='gan'

order by關鍵字
用於對結果集進行排序。
select * from user order by name 預設升序
select * from user order by name desc 降序
select * from user order by name,pwd




select的top,limit,rownum子句
SQL Servel/MS Access支援top
TOP 子句用於規定要返回的記錄的數目
select top 5 * from user //取前五行
select top 50 percent *from user//前百分之50

MySQL支援Limit
select * from user limit 3 //取前三行

Oracle支援rownum
select * from user where rownum<=5//前五行

sql Like操作符

用於在 WHERE 子句中搜索列中的指定模式

select * from user where id like 0;
sql萬用字元
% 代替0個或多個字元
_代替一個字元
[charlist]	字元列中的任何單一字元
[^charlist] 不在字元列中的單一字元
或
[!charlist]	

select *from user where name regexp '^[gfs]' //gfs開頭
'^[A-H]' //A到H開頭
'^[^A-H]'//不以A到H開頭

sql IN 操作符
IN 操作符允許在 WHERE 子句中規定多個值。
select * from user id in(0,1)
sql between操作符
用於選取介於兩個值之間的資料範圍內的值
select * from user where ID between 1 and 10;
not between //不在範圍內
sql 別名
select user.ID as I from user 
select ID concat(pwd,",",name) as other from user //合併其他屬性
sql 連線(join)
inner join 語法
select user.ID from user 
inner join books on user.id=books.autherid
或者
select user.ID from user 
join books on user.id=books.autherid

left join 語法
select user.ID from user 
left join books on user.id=books.autherid
或者
select user.ID from user 
left outer join books on user.id=books.autherid

right join/ right outer join
FUll outer join
sql uinon操作符
UNION 操作符用於合併兩個或多個 SELECT 語句的結果集。
請注意,UNION 內部的每個 SELECT 語句必須擁有相同數量的列。列也必須擁有相似的資料型別。同時,每個 SELECT 語句中的列的順序必須相同。
select ID from user
unio
select autherid from books;//unio不顯示重複,重複使用unio all

update

update user
set pwd=1222 where id=0 //必須要寫where語句,不然全部都會更新

delete

delete from user
where id=0;

delete from user
或
delete * from user//刪除所有資料

insert into

用於向表中插入新記錄
insert into user
values(0,1234,gan);

insert into user(ID,PWD,NAME)
values(0,1234,gan);
select into語句
從一個表複製資料,然後把資料插入到另一個表中
select *
into newtable [in externaldb]
from user;
或者只複製希望的列
select ID
into newtable [in externaldb]
from user

insert into select語句
從一個表複製資料,然後把資料插入到一個已存在的表中
insert into table2
select * from table1;
或者 只複製希望的列插入到另一個已存在的表中
insert into table2(id)
select id from table1;

create datebase

create datebase dbname;

alter datebase

create table

create table table_name

(

column_name1 date_type(size),

column_name2 date_type(size),

column_name3 date_type(size),

....

);

sql約束(constraints)
  • NOT NULL - 指示某列不能儲存 NULL 值。

  • UNIQUE - 保證某列的每行必須有唯一的值。

  • PRIMARY KEY - NOT NULL 和 UNIQUE 的結合。確保某列(或兩個列多個列的結合)有唯一標識,有助於更容易更快速地找到表中的一個特定的記錄。

  • FOREIGN KEY - 保證一個表中的資料匹配另一個表中的值的參照完整性。

  • CHECK - 保證列中的值符合指定的條件。

  • DEFAULT - 規定沒有給列賦值時的預設值

sql auto increment欄位

新記錄插入表中時生成一個唯一的數字。


alter table

用於在已有的表中新增、刪除、或修改列
alter table  table_name
ADD column_name datetype

修改資料型別
alter table table_name
alter column column_name datatype

刪除列
alter table table_name
drop column column_name 

drop table

drop table table_name

僅需要刪除表內的資料,但並不刪除表本身

truncate table table_name

create index

在表中建立索引

在不讀取整個表的情況下,索引使資料庫應用程式可以更快地查詢資料。

create index index_name

on table_name(columu_name)

drop index

drop index table_name.index_name