首頁 > 專家說

SQLSERVER 增刪改語句是如何寫的?常用的都有那些函數(shù),具體用法簡(jiǎn)單描述下!

來源:新能源網(wǎng)
時(shí)間:2024-08-17 13:27:22
熱度:

SQLSERVER 增刪改語句是如何寫的?常用的都有那些函數(shù),具體用法簡(jiǎn)單描述下!【專家解說】:一、增刪改查SQL語法: 1.查詢語句 第一種法方: select 列名 from

【專家解說】:一、增刪改查SQL語法: 1.查詢語句 第一種法方: select 列名 from table(數(shù)據(jù)庫表名) where(條件) 第二種法方: select *(表示所有的列) from table(數(shù)據(jù)庫表名) where(條件) 注意:列名與列名之間用逗號(hào)分開。 eg: 1.select ProductID,ProductName,Price from Product where Price>5.0 2.select * from Product where Price>5.0 3.如何給列加漢子名稱: 格式:“‘列標(biāo)題’=列名” 或 “'列名'AS 列標(biāo)題” eg: select ProductID=‘產(chǎn)品編號(hào)’,ProductName,Price from Product where Price>5.0 select '產(chǎn)品編號(hào)'as ProductID,ProductName,Price from Product where Price>5.0 where 語句中可以使用邏輯運(yùn)算符 AND OR NOT eg: select ProductID,ProductName,Price from Product where Price>=5.0 And Price<=10.0 2.使用字符串模糊匹配 格式: expression[not] like 'string'(escape"換碼字符") 3.使用查詢列表 如果列的取值范圍不是一個(gè)連續(xù)的區(qū)間,而是一些離散的值,此時(shí)就應(yīng)使用 SQL Server 提供的另一個(gè)關(guān)鍵字 IN 。 語法格式:column_name [not] IN (value1,value2....) eg: select SaleID,SaleName,Sex,Birthday,HireDate,Address form Seller where SaleID IN('S01','S02',S07) 4.空值的判定 在SQL Server中,通過null。 5.top 和 distinct 語法:select top integer || top interger percent columnName from tableName eg: 分別從Customer表中檢索出前5個(gè)及表中前20%的顧客信息。 select top 5 * from Customer select top 20 percent * from Customer 查詢Product 表中價(jià)格最高的6種商品。 eg: select top 6 * from Product order by price desc asc(低—>高) desc(高->低) 2.向表中插入數(shù)據(jù) 語法:insert into tableName(columnName...(要插入的數(shù)據(jù)的列名)) values(expression(與columnName相對(duì)應(yīng)的值)) 注意:再插入數(shù)據(jù)時(shí),對(duì)于允許為空的列可以使用NUll插入空值;對(duì)于具有默認(rèn)值的列,可使用Defaulf插入默認(rèn)值。 eg: 向Seller 表中插入一行數(shù)據(jù),其中Sex字段使用默認(rèn)值為‘男’,HireDate等字段均去空值。 insert into seller(saleid,saleName,sex,birthday,hireDate,address,telephone,telephone,notes) values('s11','趙宇飛',default,'1974-07-25',null,null,null,null) or insert into seller(saleid,saleName,brithday) values('s11','趙宇飛','1974-07-25') 3.修改表中的數(shù)據(jù) 語法:update tableName set columnName=expression(...) where search_conditions eg: 1.將Product表中"啤酒"的價(jià)格改為4元 update product set price=4 where productName='啤酒'(注意:一定要加條件 +“where”) 4.刪除數(shù)據(jù) 語法:delete [from] tableName where search_conditions eg: delete from Seller where SaleID='s11'(注意:一定要加條件 +“where”,不然就把該表中所有的數(shù)據(jù)刪除了)
  1. 英語句子摘抄及翻譯
    2024-08-17
  2. 用波浪線畫出描寫小女孩死后神態(tài)、動(dòng)作的語句。讀一讀,想想作者為什么要這樣描寫?
    2024-08-17
  3. 勤儉節(jié)約的作文 600字 語句通順 用詞好 貼近生活
    2024-08-17
  4. 哪位能幫我用matlab 計(jì)算自然對(duì)數(shù)的底e,要用兩種方法,坐等,要函數(shù)過程加結(jié)果,謝了??!
    2024-08-17
  5. 求幫忙翻譯一下,要語句通順的,謝謝
    2024-08-17
  6. 市煤氣公司要在地下修建一個(gè)容積為104立方米的圓柱形儲(chǔ)存室。寫出儲(chǔ)存室的底面積與其深度的函數(shù)關(guān)系式
    2024-08-17
  7. 麻煩哪位能幫忙吧這些翻譯語句給整理通順啊
    2024-08-17
  8. 勤儉節(jié)約的作文 600字 語句通順 用詞好 貼近生活 麻煩大家啊
    2024-08-17
  9. 請(qǐng)幫我找一些感慨物是人非的語句
    2024-08-17
  10. 誰有英語短語句型
    2024-08-17
  11. 關(guān)于朋友離別的祝福語、不要求語句優(yōu)美,只要求可以溫馨、
    2024-08-17
  12. C++中,void 為什么能當(dāng)形式參數(shù)表,不能當(dāng)函數(shù)名? 在線等!
    2024-08-17
  13. sql server 2008 T-SQL語句 表名需要用[]括起來才能正常運(yùn)行,怎么去掉這個(gè)[],求幫忙!
    2024-08-17
  14. 語文 數(shù)學(xué) 英語 綜合 平均分 邱雪 94 96 97 92 用AVERAGE函數(shù)算 計(jì)算公式要LEFT關(guān)鍵字 怎么算 ?
    2024-08-17
  15. linux shell中if 語句想要then后什么也不執(zhí)行,關(guān)鍵詞是什么?
    2024-08-17