sql创建表的时候设置主键、标识、字段字段额外属性(如说明)以及默认值

USE [DBName]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE TABLE [dbo].[TabStudent](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[ugid] [int] NOT NULL,
[sex] [int] NOT NULL,
[age] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


GO


EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用户id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TabStudent', @level2type=N'COLUMN',@level2name=N'id'
GO


EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组别id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TabStudent', @level2type=N'COLUMN',@level2name=N'ugid'
GO


EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'性别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TabStudent', @level2type=N'COLUMN',@level2name=N'sex'
GO


EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'年龄' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'TabStudent', @level2type=N'COLUMN',@level2name=N'age'
GO


ALTER TABLE [dbo].[TabStudent] ADD  DEFAULT ((1)) FOR [ugid]
GO

ALTER TABLE [dbo].[TabStudent] ADD  DEFAULT ((1)) FOR [sex]
GO

ALTER TABLE [dbo].[TabStudent] ADD  DEFAULT ((18)) FOR [age]
GO



你可能感兴趣的:(数据库,sql,server)