⑴ 数据库中我想要批量插入数据SQL语句怎么写。
用sql语句即可实现,实例如下:
INSERT INTO `ad` (`id`, `title`, `type_id`, `source`, `remark`, `pic`, `pic1`, `content`, `filepath`, `in_date`, `if_ding`, `hit_count`, `ad_type`, `imgurl`) VALUES
(1, '频道页保健学堂', 1, NULL, '', '20110713hxAWPrUv.jpg', NULL, '', '', '2011-07-13', 50, 0, 'pic', '#'),
(2, '频道页养生长寿', 1, NULL, '', '20110713SgCywdqe.jpg', NULL, '', '', '2011-07-13', 50, 0, 'pic', '#');
⑵ 如何向一个sql sever 数据库表中插入大量数据
一次性插入大量数据,只能使用循环,
如:游标,while 循环语句
下面介绍While 循环插入数据,
SQL 代码如下:
IF OBJECT_ID('dbo.Nums') IS NOT NULL
DROP TABLE dbo.Nums;
GO
CREATE TABLE dbo.Nums(n INT NOT NULL PRIMARY KEY);
DECLARE @max AS INT, @rc AS INT;
SET @max = 5000000;
SET @rc = 1;
INSERT INTO Nums VALUES(1);
WHILE @rc * 2 <= @max
BEGIN
INSERT INTO dbo.Nums SELECT n + @rc FROM dbo.Nums;
SET @rc = @rc * 2;
INSERT INTO dbo.Nums SELECT n + @rc FROM dbo.Nums WHERE n + @rc <= @max;
--以上函数取自Inside SQL Server 2005: T-SQL Query一书。
INSERT dbo.Sample SELECT n, RAND(CAST(NEWID() AS BINARY(16))) FROM Nums