加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLSERVER操作实例

发布时间:2020-12-12 15:59:22 所属栏目:MsSql教程 来源:网络整理
导读:if?exists(select?*?from?master.dbo.sysdatabases?where?name?=?'yexinwinners') begin drop?database?yexinwinners print?'yexinwinners己存在,己被删除' end else begin create?database?yexinwinners on?primary ( name?=?yexinwinners_mdf,filename?=?
if?exists(select?*?from?master.dbo.sysdatabases?where?name?=?'yexinwinners') begin drop?database?yexinwinners print?'yexinwinners己存在,己被删除' end else begin create?database?yexinwinners on?primary ( name?=?yexinwinners_mdf,filename?=?'c:/yexinwinners.mdf',size?=?10mb,maxsize?=?50mb,filegrowth?=?25% ) log?on ( name?=?yexinwinners_ldf,filename?=?'c:/yexinwinners.ldf',filegrowth?=?25% ) print?'yexinwinners?数据库创建成功' end #2?-?yexinwinners?-?2007-10-15?0:30:37 --建聚集索引 create?clustered?index?index_yexinwinners on?tablename(column_name) with?fillfactor?=?10 --建非聚集索引 create?nonclustered?index?index_yexinwinners on?tablename(column_name) with?fillfactor?=?10 --建视图 create?view?view_name as select?*?from?pubs.titles(sql语句,任意) --建检查视图 create?view?view_name as select?*?from?pubs.titles(sql语句,任意) with?check?option --建加密视图 create?view?view_name with?encryption as select?*?from?pubs.titles(sql语句,任意) --建表 create?table?tablename (?---(字段名,字段类型?自己任意) stuID?int?not?null?identity(1,1)?primary?key,stuName?varchar(30)?not?null,stuAge?char(3)?not?null ) --添加check约束 alter?table?tablename add?check(stuAge?>0?and?stuAge?<100) --添加外键 alter?table?tablename add?foreign?key?(stuName) references?Xtablename(stuName) --添加唯一约束 alter?table?tablename add?unique(stuID) #3?-?yexinwinners?-?2007-10-15?0:31:05 ---建事务 begin?tranaction update?Xtable?set?Money?=?Money?+?10000?where?ID?=?1 update?Xtable?set?Money?=?Money?-?10000?where?ID?=?3 if(@@error?<>?0) begin print?'转帐失败' rollback?transaction end else begin print?'转帐成功' commit?transaction end --建游标 declare?cursor_name?Cursor for?select?*?from?northwind.product --建更新游标 declare?cursor_name?Cursor for?select?*?from?northwind.product for?update --建随意移动游标 declare?cursor_name?Cursor?scroll for?select?*?from?northwind.product --使用游标 open?cursor_name --关闭游标 close?cursor_name --删除游标 deallocate?cursor_name --移动游标 fetch?next?--?下一条记录 fetch?last?--最后一条记录 fetch?first?--第一条记录 fetch?prior?--上一条记录 fetch?ABSOLUTE?n?--?绝对位置? ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读