⑴ 資料庫中我想要批量插入數據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