SQL server 筆記8

來源:互聯網
上載者:User

標籤:

---分頁查詢select top 2 *from student where sno not in (select top 2 sno from student) --not in() 屏蔽掉前兩行 在此基礎上再取前兩行--分頁的預存程序   --直接用輸入參數當作表名和列名,無法被識別,先用‘++‘拼接成字串,然後用exec去執行,exec依然會把這個字串當作語句執行create proc fenye1@nowye int ,--當前頁@number int,--顯示行數@tablename varchar(50),--表名@zhujian varchar(50)--主鍵名asexec ( ‘select top (‘+@number+‘) *from ‘+@tablename+‘ where ‘+@zhujian+‘ not in(select top ((‘+@nowye+‘-1)*‘+@number+‘) ‘+@zhujian+‘ from ‘+@tablename+‘)‘)goexec fenye1 2,1,‘student‘,‘sno‘---約束:對列的資料值起一個約束的作用,規定列的值的範圍--主鍵,外鍵,非空,自增長表示列,唯一列,check約束--check約束,找到表,右鍵設計--選擇列,右鍵check約束--添加--運算式(運算式必須以列名開頭)---預存程序累加求和create proc leijiaqiuhe@a int --輸入參數as    declare @b int --聲明變數    declare @i int--聲明變數    set @i=1 --賦初始值    set @b=0 --賦初始值    while @i<=@a --while迴圈條件    begin        set @b=@b+@i         set @i=@i+1 --i++    end    return @bgodeclare @c intexec @c=leijiaqiuhe 10print @c-------備份還原 --右鍵資料庫---任務--備份:在不影響資料庫正常啟動並執行情況下,將資料備份到一個.bak結尾的檔案夾--還原:將bak檔案還原到資料庫-----分離、附加--分離:將資料庫與資料庫服務進行分離--附加:將資料庫mdf檔案,附加到資料庫服務上
-----視圖:虛擬表--create view view_1--as--go--相當於把一段查詢語句起了一個別名--視圖,當作一個虛擬表--子查詢,將子查詢查詢出的結果集,當作虛擬暫存資料表來使用  (子查詢語句)as + 別名

 

 

 

SQL server 筆記8

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.