SQL SERVER基础教程之定义表

1 表中的数据类型

varchar  最大长度8000字符;超过8000则使用varchar(max),不要用text类型,因为要被取代了.

2 创建表

-- =========================================
-- Create table template
-- =========================================
USE ApressFinancial
GO

IF OBJECT_ID('TransactionDetails.TransactionTypes', 'U') IS NOT NULL
  DROP TABLE TransactionDetails.TransactionTypes
GO

CREATE TABLE TransactionDetails.TransactionTypes
(
    TransactionTypeId int identity(1,1) NOT NULL, 
    TransactionDescription nvarchar(30) not null, 
    CreditType bit not null
)
GO
--向表中插入一列,该列是NULL值
alter table TransactionDetails.TransactionTypes
add AffectCashBalance bit null
go
--再次修改列,需要再次定义数据类型,并且改为不允许有NULL值(update表后)
alter table TransactionDetails.TransactionTypes
alter column AffectCashBalance bit not null
go

 

posted @ 2021-05-29 16:30  Captain_Amazing  阅读(275)  评论(0编辑  收藏  举报