sqlserver2008r2建表語句優化
USE [master];
GO
DROP DATABASE [mydata];
GO
CREATE DATABASE [mydata];
GO
USE [mydata];
GO
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'),
[address] [nvarchar](max) NOT NULL DEFAULT (N'無'),
[idnumber] [varchar](max) 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 ([address]) values (N'北京市');
insert into t_user ([idnumber]) values ('0');
declare @i int;
set @i = 0;
while @i < 240
begin
insert into t_user ([username], [gender], [birthday], [address], [idnumber]) values (N'七七', 'f', '1980-1-1', N'北京市東城區2號', '110101198001010010');
set @i = @i + 1
end
select username as 姓名,gender as 性別,birthday as 出生年月, address as 地址,idnumber as 身份證 from t_user;