成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

NEWID創(chuàng)建 uniqueidentifier 類型的唯一值

2010-08-28 10:50:18來源:西部e網(wǎng)作者:

NEWID
創(chuàng)建 uniqueidentifier 類型的唯一值。

語法
NEWID ( )

返回類型
uniqueidentifier

示例
A.對變量使用 NEWID 函數(shù)
下面的示例使用 NEWID 對聲明為 uniqueidentifier 數(shù)據(jù)類型的變量賦值。在測試該值前,將先打印 uniqueidentifier 數(shù)據(jù)類型變量的值。

-- Creating a local variable with DECLARE/SET syntax.
DECLARE @myid uniqueidentifier
SET @myid = NEWID()
PRINT 'Value of @myid is: '+ CONVERT(varchar(255), @myid)

下面是結(jié)果集:

Value of @myid is: 6F9619FF-8B86-D011-B42D-00C04FC964FF

 

說明  對于每臺計算機,由 NEWID 返回的值不同。所顯示的數(shù)字僅起解釋說明的作用。


B.在 CREATE TABLE 語句中使用 NEWID
下面的示例創(chuàng)建具有 uniqueidentifier 數(shù)據(jù)類型的 cust 表,并使用 NEWID 將默認(rèn)值填充到表中。為 NEWID() 賦默認(rèn)值時,每個新行和現(xiàn)有行均具有 cust_id 列的唯一值。

-- Creating a table using NEWID for uniqueidentifier data type.
CREATE TABLE cust
(
 cust_id uniqueidentifier NOT NULL
   DEFAULT newid(),
 company varchar(30) NOT NULL,
 contact_name varchar(60) NOT NULL,
 address varchar(30) NOT NULL,
 city varchar(30) NOT NULL,
 state_province varchar(10) NULL,
 postal_code varchar(10) NOT NULL,
 country varchar(20) NOT NULL,
 telephone varchar(15) NOT NULL,
 fax varchar(15) NULL
)
GO
-- Inserting data into cust table.
INSERT cust
(cust_id, company, contact_name, address, city, state_province,
 postal_code, country, telephone, fax)
VALUES
(newid(), 'Wartian Herkku', 'Pirkko Koskitalo', 'Torikatu 38', 'Oulu', NULL,
 '90110', 'Finland', '981-443655', '981-443655')
INSERT cust
(cust_id, company, contact_name, address, city, state_province,
postal_code, country, telephone, fax)
VALUES
(newid(), 'Wellington Importadora', 'Paula Parente', 'Rua do Mercado, 12', 'Resende', 'SP',
 '08737-363', 'Brazil', '(14) 555-8122', '')
INSERT cust
(cust_id, company, contact_name, address, city, state_province,
 postal_code, country, telephone, fax)
VALUES
(newid(), 'Cactus Comidas para Ilevar', 'Patricio Simpson', 'Cerrito 333', 'Buenos Aires', NULL,
 '1010', 'Argentina', '(1) 135-5555', '(1) 135-4892')
INSERT cust
(cust_id, company, contact_name, address, city, state_province,
 postal_code, country, telephone, fax)
VALUES
(newid(), 'Ernst Handel', 'Roland Mendel', 'Kirchgasse 6', 'Graz', NULL,
 '8010', 'Austria', '7675-3425', '7675-3426')
INSERT cust
(cust_id, company, contact_name, address, city, state_province,
 postal_code, country, telephone, fax)
VALUES
(newid(), 'Maison Dewey', 'Catherine Dewey', 'Rue Joseph-Bens 532', 'Bruxelles', NULL,
 'B-1180', 'Belgium', '(02) 201 24 67', '(02) 201 24 68')
GO

C. 使用 uniqueidentifier 和變量賦值
下面的示例聲明局部變量 @myid 為 uniqueidentifier 數(shù)據(jù)類型。然后使用 SET 語句為該變量賦值。

DECLARE @myid uniqueidentifier
SET @myid = 'A972C577-DFB0-064E-1189-0154C99310DAAC12'
GO

原文地址: http://blog.csdn.net/pclogic/archive/2006/05/20/746509.aspx

關(guān)鍵詞:SQLServer
主站蜘蛛池模板: 察隅县| 修文县| 江都市| 祁门县| 岗巴县| 娄烦县| 阆中市| 韩城市| 大荔县| 斗六市| 韶关市| 阿图什市| 奉节县| 乡宁县| 南岸区| 大同市| 色达县| 潮安县| 米泉市| 丹寨县| 五家渠市| 施甸县| 阳山县| 宕昌县| 盐山县| 同江市| 洪泽县| 万安县| 嵩明县| 宜春市| 常州市| 莎车县| 独山县| 溧阳市| 泊头市| 四平市| 腾冲县| 中西区| 辽阳市| 原平市| 巫山县|