SQL server 数据库——T-SQL语句基础
T-SQL語句基礎(chǔ)
1.創(chuàng)建數(shù)據(jù)庫:create datebase 數(shù)據(jù)庫名
2.刪除數(shù)據(jù)庫:delete datebase 數(shù)據(jù)庫名
3.注釋:/*一段 */ ? ? ? ? ? ?一行 --
4.創(chuàng)建表:create table 表名
? ?(
? ? ?列名 ?數(shù)據(jù)類型 ?identity(1,1),--自增列,從1開始,增量為1
? ? ?列名 ?數(shù)據(jù)類型 ?primary key,--設(shè)置主鍵
? ? ?列名 ?數(shù)據(jù)類型 ?unique,--設(shè)置唯一鍵
? ? ?列名 ?數(shù)據(jù)類型 ?not null,--不能為空
? ?)
5.刪除表:delete table 表名
6.修改表結(jié)構(gòu): ???添加一行:alter table 表名 add 列名 數(shù)據(jù)類型 —— ?(注意添加的一列不能為空,要想添加一列可為空的列,刪了重建)
? ? ? ? ? ? ? ? ? ? ? ? ?刪除一行:alter table 表名 drop ?column 列名
7.添加數(shù)據(jù):insert into 表名 values('varchar','datetime',99.5)——varchar、datetime類型要用單引號,int類型直接寫
8.修改數(shù)據(jù):?update 表名 set 列名 =值——多個(gè)列名用逗號隔開
9.刪除數(shù)據(jù): ?delete from 表名——逐條刪除,記錄在日志中,序列號不更新,速度慢
? ? ? ? ? ? ? ? ? ?truncate table 表名——清空,無記錄,更新序列,速度快(慎用)
10.查詢數(shù)據(jù): select * from 表名
============================================================================
11.條件修改: update 表名 set 列名1=值1 where 列名2=值2 ? ——將表中列名1中的值改成值1 當(dāng)列名2中為值2時(shí)
12.條件刪除:delete from 表名 where 列名=值
13.排序查詢:select *from 表名 order by 列名 ?asc(升序)/desc)(降序)
14.去重查詢:select distinct 列名 from 表名 ——不能查全部列,只能顯示一列
15.分組查詢:select 列名 from 表名 group by 列名?——不能查全部列,只能顯示一列
16.模糊查詢:select *from 表名 where 列名 like '%查詢內(nèi)容%'order by price by desc
17.子查詢:將查詢語句當(dāng)做值使用
? ? ? ? ? ?
?
轉(zhuǎn)載于:https://www.cnblogs.com/weiyu11/p/6531295.html
總結(jié)
以上是生活随笔為你收集整理的SQL server 数据库——T-SQL语句基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对手机图标整理事件总结
- 下一篇: Mysql错误问题:ERROR 1005