你是要用SQL语句插入数据吗?如果是的话你就用这个试下
create table MyDB
(
ID int primary key identity(1,1),
Name nvarchar(50) not null,
Salary int not null,
Age int not null
)
insert into MyDB(Name,salary,age) values('小明',5000,20)
insert into MyDB(Name,salary,age) values('王二虎',3580,22)
insert into MyDB(Name,salary,age) values('王中出',4122,19)
insert into MyDB(Name,salary,age) values('方为',5122,28)
select name as 姓名,salary as 工资,age as 年龄 from mydb
建表,插入,查询语句都有。同时执行分段执行都可以。。
insert是插入数据,select是查询数据。
create table 是建表语句!
要建2各表。
1A表ID建(类似于类别)
2B表NAME建(类似于新闻条数)
添加B表多条信息的时候,可以同时添加A表的ID,B表里就是NAME内容不一样。ID就是相同的。
--试试下面的方法
--2005
DECLARE @n AS BIGINT;
SET @n = 1000000;
WITH Base AS
(
SELECT 1 AS n
UNION ALL
SELECT n + 1 FROM Base WHERE n < CEILING(SQRT(@n))
),
Expand AS
(
SELECT 1 AS c
FROM Base AS B1, Base AS B2
),
Nums AS
(
SELECT ROW_NUMBER() OVER(ORDER BY c) AS n
FROM Expand
)
SELECT n FROM Nums WHERE n <= @n
OPTION(MAXRECURSION 0);
--2
CREATE FUNCTION dbofn_nums(@n AS BIGINT) RETURNS TABLE
AS
RETURN
WITH
L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
L3 AS(SELECT 1 AS c FROM L2 AS A, L2 AS B),
L4 AS(SELECT 1 AS c FROM L3 AS A, L3 AS B),
L5 AS(SELECT 1 AS c FROM L4 AS A, L4 AS B),
Nums AS(SELECT ROW_NUMBER() OVER(ORDER BY c) AS n FROM L5)
SELECT n FROM Nums WHERE n <= @n;
GO
--2000 这个会比前两个慢,但是前两个2000不能用
CREATE TABLE dboNums(n INT NOT NULL PRIMARY KEY);
DECLARE @max AS INT, @rc AS INT;
SET @max = 1000000;
SET @rc = 1;
INSERT INTO Nums VALUES(1);
WHILE @rc 2 <= @max
BEGIN
INSERT INTO dboNums SELECT n + @rc FROM dboNums;
SET @rc = @rc 2;
END
INSERT INTO dboNums
SELECT n + @rc FROM dboNums WHERE n + @rc <= @max;
以上就是关于sql数据库中怎么插入多个表中的数据全部的内容,包括:sql数据库中怎么插入多个表中的数据、sql中添加一列中的多条数据、SQL SERVER 一次插入多条数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)