tsql創建表
發布時間: 2024-01-26 02:51:22
㈠ Test資料庫中,用T-sql語句創建員工工資表,各列的要求如 下表所示
CREATETABLEdbo.員工工資
(
NointNOTNULLIDENTITY(1,1),
Xmvarchar(30)NOTNULL,
Gzdecimal(8,2)NOTNULL,
YwJjdecimal(8,2)NOTNULL,
Sdsdecimal(8,2)NOTNULL,
SfGzASGz+YwJj-Sds
)ON[PRIMARY]
GO
DECLARE@vsql_variant
SET@v=N'員工工資'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',NULL,NULL
GO
DECLARE@vsql_variant
SET@v=N'編號'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',N'COLUMN',N'No'
GO
DECLARE@vsql_variant
SET@v=N'姓名'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',N'COLUMN',N'Xm'
GO
DECLARE@vsql_variant
SET@v=N'工資'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',N'COLUMN',N'Gz'
GO
DECLARE@vsql_variant
SET@v=N'業務獎金'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',N'COLUMN',N'YwJj'
GO
DECLARE@vsql_variant
SET@v=N'所得稅'
EXECUTEsp_addextendedpropertyN'MS_Description',@v,N'SCHEMA',N'dbo',N'TABLE',N'員工工資',N'COLUMN',N'Sds'
GO
ALTERTABLEdbo.員工工資ADDCONSTRAINT
PK_員工工資PRIMARYKEYCLUSTERED
(
No
)WITH(STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
GO
ALTERTABLEdbo.員工工資SET(LOCK_ESCALATION=TABLE)
GO
㈡ t sql 建好表後如何定義主鍵
tsql建好表後如何定義主鍵的方法。
如下參考:
1、打開管理工具,SQLServerManagementStudio連接到資料庫。
熱點內容