DECLARE @LN varchar, @MN varchar ($), @FN varchar (200)
DECLARE @LN_N int, @MN_N int, @FN_N int
SET @LN = ' Li Wang Changliuxun Jumahu Goulin Hegorang Feng Funzheng Cheng Dudinshen Fu Jong Luwang Dai Tri Liao Yaofang Kin Chuxia Tan Weija Xun Meng Qin Yu 薛侯雷白龙 段郝孔 邵史毛 often 万顾赖武康 贺严 尹钱施牛洪 gong '
SET @MN = ' Dessau Zongbongyufu Jia Chang Koritaka Friends of the Cheng Tai Ching Zheng Kai Shi is bound to Zhong Yuanqui Peacock laid first ze far Yong Sheng Ninva Surung '
SET @FN = ' li Yunfeng Lei bright macro red Hong Shiliang Liang Liang Grain liang Seven flags qi qi 牟弭 Mimi lei class Lei rib Qing Qing-Qing hing-xing Lucky Star punishment '
SET @LN_N =len (@LN)
SET @MN_N =len (@MN)
SET @FN_N =len (@FN)
DECLARE @TMP VARCHAR (+), @i INT
SET @i=100
While @i<1000000
BEGIN
SET @TMP =cast (SUBSTRING (@LN, CAST (RAND () * @LN_N as INT), 1) as VARCHAR)
SET @[email protected]+cast (SUBSTRING (@MN, CAST (RAND () * @MN_N as INT), 1) as VARCHAR)
SET @[email protected]+cast (SUBSTRING (@FN, CAST (RAND () * @FN_N as INT), 1) as VARCHAR)
INSERT into student (sno,sname) VALUES (' 2005 ' [email protected], @TMP)
SET @[email protected]+1
End
---from the Internet, if there is infringement, please leave a message!
Create a new query in SQL Server to bulk insert data, previously always thought to write a stored procedure in order to BULK insert it ...
Cast and convert are all used for type conversions, functionally the same, except that the syntax is different, cast is easier to use, and convert has the advantage of formatting the date and time;
Here are some examples of http://www.cnblogs.com/davidgu/archive/2011/02/15/1955335.html to learn
Select CAST (' 123 ' as int)--123
Select CONVERT (int, ' 123 ')--123
Select CAST (123.4 as int)--123
Select CONVERT (int, 123.4)--123
Select CAST (' 123.4 ' as int)
Select CONVERT (int, ' 123.4 ')
--Conversion failed when converting the varchar value ' 123.4 ' to data type int.
Select CAST (' 123.4 ' as decimal)--123
Select CONVERT (Decimal, ' 123.4 ')--123
Select CAST (' 123.4 ' as Decimal (9,2))--123.40
Select CONVERT (Decimal (9,2), ' 123.4 ')--123.40
DECLARE @Num Money
Set @Num = 1234.56
Select CONVERT (varchar (0), @Num,)--1234.56
Select CONVERT (varchar), @Num, 1)--1,234.56
Select CONVERT (varchar (2), @Num,)--1234.5600
"SQL Server" BULK INSERT 100,000 data