sqlserver 知識點 1

來源:互聯網
上載者:User

標籤:使用   總數   between   子查詢   tween   資料   注意   ext   彙總函式   

資料庫知識點

1.資料庫操作:

增:insert into 表名 values(值1,值2,值3)

刪:delete 列名 from 表名 where
條件

改:update 表名 set =值 where
表名=值

查:select * from username 全部
select name from username

2.彙總函式:
2.1 sql aggregate

sum() 計算總數
max() 計算最大數
mix() 計算最小數
count() 計算總數
avg() 計算
last() 最後一個值


2.2sqlscalar
len() 文本字元的長度 mid()從某個位元組提取字元的前四個數 rount()對指定小數點進行四捨五入 now 返回當前日期和時間 format()格式化字元的顯示方式 lcase() 將字元小寫 ucase() 大寫

3.過濾:

where :is null 判斷是否為null
or:或者
not:非
in(set):是否在一個集合裡面
between..and >=且 <=
><=< => 符號

4.多錶鏈接

注意:

主鍵表的條件約束應該和外鍵表的條件約束一致

內連結
inner join 表名 on 條件

外串連:
(左連結)
left join 表名 on 條件
(右連結)
right join 表名 on 條件

全連結:full outer join();

分組查詢:group by having
分組查詢用彙總函式篩選出結果,然後在分組之前的條件進行查詢

排序 : 將列的結果進行排序
order ASC|DESC

子查詢: 例:select * from customers where id in(select id from custmers where salary>4500)
例2:select column_name[column_name] from table[table2]
where column_name operator
(select column_name[column_name ] from table1[tablee2] [where])

5.組合查詢 將兩個表合并成一個表
union 合并值
union all 可選取重複的值

6.select 萬用字元號* 查詢所有的
別名 as 查詢新行並且改名
計算欄位拼接 +||,concat()

去除重複的記錄 distinct


建立表 字元類型:character 字串 text,varchar,char(size)儲存固定長度的字串

unlcode 字串 nchar(),ntext()
binary 類型 bit bitary image
varbinary

number 類型 int,money,float,bigint,tinint

date類型:datetime,data

其他資料類型:xml,cursor

常用的欄位選擇:金額貨幣選擇用money 類型
自增長用bigint 類型
時間類型用datetime 類型
盡量不要使用text,ntext,image類型
盡量不用xml類型

約束:主鍵 非空唯一
非空
惟一
主鍵自增長
外鍵 一張表可以關聯另外一張表,保證資料完整性
DEFAULT 約束用於列中插入預設值


更新表 alter add
查詢表 show tables
desc 表名:查詢表的詳細資料
刪除表 drio table

 

sqlserver 知識點 1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.