<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
Ctrl+Shift+R
select *from [table]
UPDATE [table] set [欄位]=[values]
UPDATE A SET A1 = B1, A2 = B2, A3 = B3 FROM A, B WHERE A.ID = B.ID
delete [table]
drop [table]
select *from [table] where [欄位]=[values]
1 開始事務: begin transaction
2 提交事務:commit transaction
3 回滾事務: rollback transaction
4 結束事務: 提交或回滾事務都將結束事務
/*--開始事務--*/ begin transaction declare @errorSum int --定義變數,用於累計事務執行過程中的錯誤 /*--轉帳--*/ update bank set currentMoney=currentMoney-800 where customerName='張三' set @errorSum=@errorSum+@@error --累計是否有錯誤 update bank set currentMoney=currentMoney+800 where customerName='李四' set @errorSum=@errorSum+@@error --累計是否有錯誤 print '檢視轉帳事務過程中的餘額' select * from bank /*--根據是否有錯誤,確定事務是提交還是回滾--*/ if @errorSum>0 begin print '交易失敗,回滾事務.' rollback transaction end else begin print '交易成功,提交事務,寫入硬碟,永久儲存!' /*--提交併且結束事務--*/ commit transaction end go print '檢視轉帳後的餘額' select * from bank go
select * from sys.tables
select * from sys.columns
select * from sys.extended_properties
SELECT t.[name] AS 表名,c.[name] AS 欄位名,cast(ep.[value] as varchar(100)) AS [欄位說明] FROM sys.tables AS t INNER JOIN sys.columns AS c ON t.object_id = c.object_id LEFT JOIN sys.extended_properties AS ep ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1 AND t.name='UTB_GBNT_PROJ_INFO'--------表名
create view ViewName (欄位1,欄位2) as ( select 欄位1, 欄位2 from [table] )
SELECT t.FieldExp 名稱,t.ColumnName 程式碼, case t.FieldDataType when 'bigint' then t.FieldDataType when 'int' then t.FieldDataType when 'datetime' then t.FieldDataType when 'numeric' then t.FieldDataType when 'nvarchar' then (cast(t.FieldDataType as varchar(100))+'('+cast(t.Fieldlength as varchar(100))+')') when 'decimal' then (cast(t.FieldDataType as varchar(100))+'('+cast(t.Fieldlength as varchar(100))+','+cast(t.Scale as varchar(100))+')') end as 資料型別 ,t.Fieldlength 長度,t.Scale 精確度 ,case t.FieldNullable when 0 then '不為空' when 1 then '' end as 說明 from (select colorder=C.column_id, FieldExp=ISNULL(PFD.[value],N''), ColumnName=C.name, FieldDataType=T.name, Fieldlength=COLUMNPROPERTY(c.object_id ,c.name ,'PRECISION'), Scale=C.scale, FieldNullable=C.is_nullable --FieldDefVal=D.definition FROM sys.columns C INNER JOIN sys.objects O ON C.[object_id]=O.[object_id] AND (O.type='U' or O.type='V') AND O.is_ms_shipped=0 INNER JOIN sys.types T ON C.user_type_id=T.user_type_id LEFT JOIN sys.default_constraints D ON C.[object_id]=D.parent_object_id AND C.column_id=D.parent_column_id AND C.default_object_id=D.[object_id] LEFT JOIN sys.extended_properties PFD ON PFD.class=1 AND C.[object_id]=PFD.major_id AND C.column_id=PFD.minor_id LEFT JOIN sys.extended_properties PTB ON PTB.class=1 AND PTB.minor_id=0 AND C.[object_id]=PTB.major_id LEFT JOIN ( SELECT IDXC.[object_id], IDXC.column_id, Sort=CASE INDEXKEY_PROPERTY(IDXC.[object_id],IDXC.index_id,IDXC.index_column_id,'IsDescending') WHEN 1 THEN 'DESC' WHEN 0 THEN 'ASC' ELSE '' END, PrimaryKey=CASE WHEN IDX.is_primary_key=1 THEN N'√'ELSE N'' END, IndexName=IDX.Name FROM sys.indexes IDX INNER JOIN sys.index_columns IDXC ON IDX.[object_id]=IDXC.[object_id] AND IDX.index_id=IDXC.index_id LEFT JOIN sys.key_constraints KC ON IDX.[object_id]=KC.[parent_object_id] AND IDX.index_id=KC.unique_index_id INNER JOIN ( SELECT [object_id], Column_id, index_id=MIN(index_id) FROM sys.index_columns GROUP BY [object_id], Column_id ) IDXCUQ ON IDXC.[object_id]=IDXCUQ.[object_id] AND IDXC.Column_id=IDXCUQ.Column_id AND IDXC.index_id=IDXCUQ.index_id ) IDX ON C.[object_id]=IDX.[object_id] AND C.column_id=IDX.column_id WHERE O.name='--tablename--')as t ORDER BY colorder,ColumnName
SELECT 表名=case when a.colorder=1 then d.name else '' end, 表說明=case when a.colorder=1 then isnull(f.value,'') else '' end, 欄位序號=a.colorder, 欄位名=a.name, 標識=case when COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 then '√'else '' end, 主鍵=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in ( SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid ))) then '√' else '' end, 型別=b.name, 佔用位元組數=a.length, 長度=COLUMNPROPERTY(a.id,a.name,'PRECISION'), 小數位數=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0), 允許空=case when a.isnullable=1 then '√'else '' end, 預設值=isnull(e.text,''), 欄位說明=isnull(g.[value],'') FROM syscolumns a left join systypes b on a.xtype=b.xusertype inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' left join syscomments e on a.cdefault=e.id left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0 --where d.name='要查詢的表' --如果只查詢指定表,加上此條件 order by a.id,a.colorder
到此這篇關於MSSQL基本語法及範例操作語句的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45