2012年11月28日 星期三

MS SQL 的資料型態


form http://codingboy.pixnet.net/blog/post.........


整數
 資料型別 說明
 INT 長度為 4 個 bytes;介於 -2,147,483,648 與 2,147,483,647 間的整數
 SMALLINT 長度為 2 個 bytes;介於 -32,768 與 32,767 間的整數
 TINYINT 長度為 1 個 bytes;介於 0 與 255 間的整數
 BIGINT 長度為 8 個 bytes;介於 -2^63 與 2^63-1 間的整數
 BIT 只佔用一個位元,且不允許存放 NULL 值
精確位數
 資料型別 說明
 DECIMAL[(p[,s])] 使用 2 到 17 個 bytes 來儲存資料,可儲存的值介於 -1038-1 與 1038-1 之間;p 用來定義小數點兩邊可以被儲存的位數總數目,而 s 代表小數點右邊的有效位數(s < p);p的預設值為 18 而 s 的預設值為0
 NUMERIC[(p[,s])] 與 DECIMAL[(p[,s])] 同
近似浮點數值
 資料型別 說明
 FLOAT[(n)] n 是儲存 float 數字的小數位數,介於 1 與 53 間;若 n 介於 1 與 24 間,儲存大小為 4 個 bytes,有效位數為 7 位數;若 n 介於 25 與 53 間,儲存大小為 8 個 bytes,有效位數為 15 位數
 REAL 長度為 4 個 bytes;介於 -3.4E-38 與 3.4E+38 間的浮點數;與 FLOAT(24) 相同
日期時間
 資料型別 說明
 DATETIME 長度為 8 個 bytes;介於 1/1/1753 與 12/31/9999 間的日期時間
 SMALLDATETIME 長度為 4 個 bytes;介於 1/1/1900 與 6/6/2079間的日期時間
字串
 資料型別 說明
 CHAR[(n)] 固定長度為 n 的字元型態,n 必須介於 1 與 8000 之間
 VARCHAR[(n)] 與 CHAR 相同,只是若輸入的資料小於 n,資料庫不會自動補空格,因此為變動長度之字串
 TEXT 用來儲存大量的(可高達兩億個位元組)字元資料,儲存空間以 8k 為單位動態增加
Unicode 字串
 資料型別 說明
 NCHAR 與 CHAR 相同,只是每一個字元為兩個 bytes 的 unicode,且 n 最大為 4000
 NVARCHAR 與 VARCHAR 相同,只是每一個字元為兩個 bytes 的 unicode,且 n 最大為 4000
 NTEXT 和 TEXT 雷同,只是儲存的是 Unicode 資料
二元碼字串
 資料型別 說明
 BINARY[(n)] 固定長度為 n+4 個 bytes; n 為 1 到 8000 的值,輸入的值必需符合兩個條件:(1) 每一個值皆為 0-9、a-f 的值;(2)每一個值的前面必須有 0X
 VARBINARY[(n)] 與 BINARY 相同,只是若輸入的資料小於 n,資料庫不會自動補 0,因此長度為變動的
 IMAGE 和 TEXT 雷同,只是儲存的是影像資料
貨幣
 資料型別 說明
 MONEY 長度為 8 個 bytes 的整數,小數點的精確度取四位
 SMALLMONEY 長度為 4 個 bytes 的整數,小數點的精確度取四位
標記
 資料型別 說明
 TIMESTAMP 8 bytes 的 16 進位值
 UNIQUEIDENTIFIER 16 bytes 的 16 進位值
其他
 資料型別 說明
 SQL_VARIANT 此資料型別可儲存 text、ntext、timestamp 與 sql_variant 以外的各種 SQL Server 支援的資料型別。
 CURSOR 查詢結果的資料集 (註:2005)
 TABLE 表格型式的資料 (註:2005)

2012年11月21日 星期三

SQL 指令WITH * AS //// (CTE)

form http://www.cnblogs.com/CareySon/archive/2011/12/12/2284740.html

利用快取 儲存一個 "常用" 的查詢結果




WITH
cr AS
(
    select * from user WHERE Name like 'C%'
)
SELECT Name from cr WHERE Name like '%A%'

SQL 測量SQL語法效能

計算SQL語法的效能



01.--訂一個開始跟結束
02.DECLARE @START DATETIME,
03.@STOP  DATETIME
04.--取得開始時間(取系統時間)
05.SET @START = GETDATE()
06.WAITFOR DELAY '00:00:00.080' --利用延遲語法來做延遲ms,在此放置SQL Script
07. 
08.--語法Start
09. 
10.SELECT  *  FROM  Employees
11. 
12.--語法End
13. 
14.--執行完了再取得執行完成時的時間(系統時間)
15.SET @STOP = GETDATE()
16.--算出二者差異的時間就是執行的時間了
17.SELECT 'The Execution took ' CONVERT(varchar(20), DATEDIFF(ms, @START, @STOP)) + ' ms'





form http://subocheng.blogspot.com/2007/05/sql-script.html


SQL 指令DECLARE


宣告 快取 變數
默認值為NULL

DECLARE @id int

         SET@id=2

         select id

SQL 排名函數: RANK() , DENSE_RANK() , ROW_NUMBER()

form http://www.cnblogs.com/xingxing-sky/archive/2012/02/08/2343043.html




RANK()
分區排名 名次並不連續
  因此,RANK 函數並不總返回連續整數。

DENSE_RANK()

分區排名  名次數字是連續性的

ROW_NUMBER()

常見的排名   連續  名次獨一

SQL 指令UNION

from http://www.1keydata.com/tw/sql/sqlunion.html

類似JOIN
是將兩個 同樣型別 的資料欄會合併

並且不會有重複的資料

類似SELECT DISTINCT

2012年11月19日 星期一

SQL PARTITION(分區) 和 OVER() 範例




partition  by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition  by用于给结果集分组,如果没有指定那么它把整个结果集作为一个分组 
create database StudentDB
go
use StudentDB
go
create table Student  --学生成绩表
(
 id int,  --主键
 Grade int, --班级
 Score int --分数
)
go
insert Student
    select 1,1,88
union all select 2,1,66
union all select 3,1,75
union all select 4,2,30
union all select 5,2,70
union all select 6,2,80
union all select 7,2,60
union all select 8,3,90
union all select 9,3,70
union all select 10,3,80
go
--所有学生信息
select * from Student
id          Grade       Score
----------- ----------- -----------
1           1           88
2           1           66
3           1           75
4           2           30
5           2           70
6           2           80
7           2           60
8           3           90
9           3           70
10          3           80
(10 行受影响)
--不分班按学生成绩排名
select *,ROW_NUMBER() over(order by Score desc) as Sequence from Student
id          Grade       Score       Sequence
----------- ----------- ----------- --------------------
8           3           90          1
1           1           88          2
6           2           80          3
10          3           80          4
3           1           75          5
9           3           70          6
5           2           70          7
2           1           66          8
7           2           60          9
4           2           30          10
(10 行受影响)
--分班后按学生成绩排名
select *,row_number() over(partition by Grade order by Score desc) as Sequence from Student
id          Grade       Score       Sequence
----------- ----------- ----------- --------------------
1           1           88          1
3           1           75          2
2           1           66          3
6           2           80          1
5           2           70          2
7           2           60          3
4           2           30          4
8           3           90          1
10          3           80          2
9           3           70          3
(10 行受影响)

2012年11月15日 星期四

javascript 讓window.open的彈出視窗置中

from http://www.pt.ntu.edu.tw/hmchai/PTcomputer/hJavaScript/JSwindow.htm
http://boray06.blogspot.tw/2011/04/windowopen.html
http://www.study-area.org/coobila/tutorial_275.html


讓window.open的彈出視窗置中
function openwindow(url,name,iWidth,iHeight)
{
  var url;     //網頁位置;
  var name;    //網頁名稱;
  var iWidth;  //視窗的寬度;
  var iHeight; //視窗的高度;
  var iTop = (window.screen.availHeight-30-iHeight)/2;  //視窗的垂直位置;
  var iLeft = (window.screen.availWidth-10-iWidth)/2;   //視窗的水平位置;
  window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',status=no,location=no,status=no,menubar=no,toolbar=no,resizable=no,scrollbars=no');
}

ASP C#如何抓javascript變數





<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Aspx_postback.WebForm2" %>   

  <!DOCTYPE html PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   

  <html   xmlns="http://www.w3.org/1999/xhtml"      >   
  <head id="Head1"   runat="server"   >   
                 <title   > Untitled   Page    </title   >   
                 <script   type="text/javascript"   >   
               
                   var   pa1   =   "Time   is"   ;  
                   function   go(){                           
                          PageMethods.cs(pa1,js);   //PageMethods.c#方法(c#接收的值,叫javascript另一方法)                      }  
                     
                   function   js(cs)  
                   {  
                         alert(cs);  
                   }  
                           

                 </script>   
  </head>   
  <body>   
                 <form  id="form2"   runat="server"   >   
                 <div>   
                             <input   type="button"   onclick="go();"   value="submits"   />   
                             <asp: ScriptManager   ID="ScriptManager1"   runat="server"   EnablePageMethods="true"/>   
                 </div>   
                 </form>   
  </body>   
  </html>   
==================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;  
namespace Aspx_postback
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        [System.Web.Services.WebMethod]
        public static string cs(string pa1)
        {
            return pa1 + DateTime.Now.ToString();
        }  
    }
}



=======================

換行符號
Page.RegisterStartupScript("scriptStr", "<script language='javascript'>alert('"+strMsg+"'\\n换行);</script>");

在JS里,换行是\n,在C#里,就需要两个“\\”来表示一个“\”
“\”在C#中是转义字符

javascript ready和onload 的區別

from http://www.ljf.cn/2010/1/Item191451.html



jq ready()的方法就是Dom Ready,他的作用或者意義就是:在DOM加載完成後就可以可以對DOM進行操作。
一般情況先一個頁面響應加載的順序是,域名解析-加載html-加載js和css-加載圖片等其他信息。
那麼Dom Ready應該在“加載js和css”和“加載圖片等其他信息”之間,就可以操作Dom了
2、Dom Load
用原生的js的時候我們通常用onload時間來做一些事情,比如:
window.onload=function(){
//do something
}
//或者經常用到的圖片,假設這個
document.getElementByIdx_x("imgID").onload=function(){
//do something
}
這種就是Dom Load,他的作用或者意義就是:在document文檔加載完成後就可以可以對DOM進行操作,document文檔包括了加載圖片等其他信息。
那麼Dom Load就是在頁面響應加載的順序中的“加載圖片等其他信息”之後,就可以操作Dom了。

[CSS] div圖層的絕對,相對及固定位置(position)

絕對位置
(以網頁左上角為基準的絕對位置)

position : adsolute;
top : 10px;
bottom : 10px;
left : 10px;
right :10px;

相對位置
(受前一個元素位置和大小的影響)

position : relative;
top : 10px;
bottom : 10px;
left : 10px;
right :10px;

固定位置
(不受網頁捲動而移動,固定在網頁上的一個位置)
※IE6以下版本完全無法支援,需要特殊方法解決 [範例網頁]

position : fixed;
top : 10px;
bottom : 10px;
left : 10px;
right :10px;

關於position的其他實驗
http://w3help.org/zh-cn/causes/RM8024
 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template