sql回顾而知新
++++++++++++++++++++++++++++++++++++++
1.數據庫的 數據類型: int ,decimal ,money,varchar(20)
? ? ? ? ? ? ? ? ? ? ? ?差不多 就可以包含所有的 事務類型
? ? ? ? ? ? ? ? ?對于 日期 就是 datatime,2001-01-02
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
2. 實體約束的問題,就是 ?primary key ,identity,not null,
? ? ? ? ? ? ? ? ? ?默認值: addr ?varchar(10) not null default '中國',?
? ? ? ? ? ? ? ? ? ? ? ? stuNo int identity(1001,1) primary key,--主鍵
? ? ? ? ? ? ? ? ? ? ?外鍵約束: classId int foreign key references Tb_class(stuNo)--其他的表的主鍵作為 外鍵
? ? ? ? 取值約束, ? ?age int check (age>=10 and age<20)
++++++++++++++++++++++++++++++++++++++++++++++++++++
3.操作語言:
? ? ? ? ? ?部分插入 ? ?insert ?T_stu(f_name,f_sex) values('馬云','男')
? ? ? ? ? ? 全部插入 ?insert T_stu values(25,'電氣','馬云','男',2001-11-14)
? ? ? ? ? ?刪除: delete from T_stu where name='馬云'
? ? ? ? ? ?刪除記錄: truncate table student
? ? ? ? ? ?更改: update T_stu set name='馬玉華' where name='馬云'
++++++++++++++++++++++++++++++++++++++++++++++++++++
4.基本查詢
? ? ? ?select ?list_xx ?into new_table
? ? from T_xx, T_XXX ?可以是一個表或者是多個表
? ?where 條件 ?group by 列名 必須是 前面會出現的?
? ? ? ? ? ? ? ? ? ? ? having 已經分組的 表 又加 條件必須 是 組列中 的一個
?order by XX asc/desc 就是根據 其 排序 ??
++++++++++++++++++++++++++++++++
? ?*** select * from teacher age>40
? ? ?where DName in ('計算機','電氣')
? ?**** CName like '%氣'
? ? ? ? ? ? ? ? ?_ 表示一個 字符
? ? ? ? ? ? ? ? ? __表示 兩個 ? like‘ [計電]’ 就是 只要 有 任意的一個 字出現就行?
+++++++++++++++++++++++++++++++
5.聚合函數
? ? 通常要和 分組命令 一起使用
??? ? 1.選中的 列的 總數 ? ? ? ?sum(sal) as 工資總數 from ?teacher where age>40
? ? ? ?2. 列中值得 個數 ? ? count(*) from teacher where sex='女'--所有女教師的人數
? ? ? ?3.某一列中 的 最大 最小 ?max(age)from TT where sex='男'
? ? ? ? ? 年齡最大 男 教師的 ?信息
? ? ? ? ? ? ? ?select * from teacher where age=(select max(age) from TT where sex='男')
? ? ? ? 4. 平均年齡的 avg(age) ??
++++++++++++++++++++++++++++++++++++++++++++++
?
轉載于:https://www.cnblogs.com/yyjxxd/p/5424777.html
總結
- 上一篇: 教你玩炸王者荣耀诸葛亮
- 下一篇: 类型参数化-泛型