哈喽,你好啊,我是雷工!
前边学习了如何用T-SQL创建数据库《数据库|基于T-SQL创建数据库》
今天继续学习基于T-SQL在数据库中创建数据表。
以下为学习笔记。
01 创建Author数据表
创建一个作者表,表名称为Author,包含作者编号,登录账号,登录密码,作者名称,手机,地址,几项内容。
创建数据表T-SQL代码与创建数据库的代码类似,
1.1、代码如下:
指向要操作的数据库
use LGAccountManagentDB
go
if exists(select*from sysobjects where name='Author')
drop table Author
go
create table Author
(
AuthorId int primary key,--作者编号,主键
LoginAccount nvarchar(50)not null,--登录账号
LoginPwd varchar(18)not null,--登录密码
AuthorName varchar(20)not null,--作者名字
Phonenumber char(11)not null,--手机
NowAddress nvarchar(100)not null--地址
)
go
1.2、选中代码,
点击【执行】按钮
1.3、点中数据库名称,
然后右击点击【刷新】,然后点击【表】下方增加了【dbo.Author】数据表。
02 创建其他数据表
同样的方法创建【账号类型表】和【账号表】
账号类型表代码为:
--账号类型表
if exists(select*from sysobjects where name='AccountType')
drop table AccountType
go
create table AccountType
(
TypeId int identity(10,1)primary key,--类型编号
TypeName varchar(20)not null--类型名称
)
go
账号表代码为:
--账号表
if exists(select*from sysobjects where name='Account')
drop table Account
go
create table Account
(
AccountId int primary key,--账号编号
AccountName varchar(20)not null,--账号名称
AccountContent nvarchar(500)not null,--账号简介
originality int not null--原创数
)
go
03 后记
以上为在数据库中通过T-SQL创建数据表的方法,下面开始向数据表中添加数据。
有同样在学相关内容的小伙伴可以点赞+在看+关注,一起学习进步。