sqlserver2008r2建表语句优化

版权声明: https://blog.csdn.net/eds124/article/details/84179168

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;

没有更多推荐了,返回首页