CREATE TABLE [dbo].[t_user]
(
[id] [int] IDENTITY(1,1) NOT NULL,
[username] [nvarchar](max) NOT NULL DEFAULT (N'无'),
[gender] [varchar](max) NOT NULL DEFAULT ('m'),
[birthday] [date] NOT NULL DEFAULT ('1900-01-01'),
[homeaddress] [nvarchar](max) NOT NULL DEFAULT (N'无'),
[idnumber] [char](18) NOT NULL DEFAULT ('0'),
PRIMARY KEY ([id])
-- CHECK ([gender]='m' OR [gender]='f')--批量插入数据时先注销这一句,因为每次检查是不是男,女和无速度会很慢.
);
insert into t_user ([username]) values (N'张三');
insert into t_user ([gender]) values ('m');
insert into t_user ([birthday]) values ('1980-1-1');
insert into t_user ([homeaddress]) values (N'北京市');
insert into t_user ([idnumber]) values ('0');
select * from (select * from mydata..t_user union all select * from mydata2..t_user union all select * from mydata3 ..t_user
union all select * from mydata4 ..t_user
union all select * from mydata5 ..t_user
union all select * from mydata6 ..t_user
union all select * from mydata7 ..t_user
union all select * from mydata8 ..t_user
union all select * from mydata9 ..t_user
union all select * from mydata10 ..t_user
) as t where username = 'df'
select count(*) from (select * from mydata..t_user union all select * from mydata2..t_user union all select * from mydata3 ..t_user
union all select * from mydata4 ..t_user
union all select * from mydata5 ..t_user
union all select * from mydata6 ..t_user
union all select * from mydata7 ..t_user
union all select * from mydata8 ..t_user
union all select * from mydata9 ..t_user
union all select * from mydata10 ..t_user
) as t
update mydata3..t_user set username = 'df' where id = 1004665
insert into mydata..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata..t_user
insert into mydata2..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata2..t_user
insert into mydata3..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata3..t_user
insert into mydata4..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata4..t_user
insert into mydata5..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata5..t_user
insert into mydata6..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata6..t_user
insert into mydata7..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata7..t_user
insert into mydata8..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata8..t_user
insert into mydata9..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata9..t_user
insert into mydata10..t_user (username, gender, birthday, homeaddress,idnumber) select username, gender, birthday, homeaddress,idnumber from mydata10..t_user
declare @i int;
set @i = 0;
while @i < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i = @i + 1
end
use mydata2
declare @i2 int;
set @i2 = 0;
while @i2 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i2 = @i2 + 1
end
use mydata3;
declare @i3 int;
set @i3 = 0;
while @i3 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i3 = @i3 + 1
end
use mydata4;
declare @i4 int;
set @i4 = 0;
while @i4 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i4 = @i4 + 1
end
use mydata5;
declare @i5 int;
set @i5 = 0;
while @i5 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i5 = @i5 + 1
end
use mydata6;
declare @i6 int;
set @i6 = 0;
while @i6 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i6 = @i6 + 1
end
use mydata7;
declare @i7 int;
set @i7 = 0;
while @i7 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i7 = @i7 + 1
end
use mydata8;
declare @i8 int;
set @i8 = 0;
while @i8 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i8 = @i8 + 1
end
use mydata9;
declare @i9 int;
set @i9 = 0;
while @i9 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i9 = @i9 + 1
end
use mydata10;
declare @i10 int;
set @i10 = 0;
while @i10 < 100000
begin
insert into t_user ([username], [gender], [birthday], [homeaddress], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市东城区2号', '110101198001010010');
set @i10 = @i10 + 1
end