1.一个计算列中不能引用另一个计算列
2.像这样
create table tt7(a int
,b int
,c int
,d as (a+b+c)/3.0
,e as (a-(a+b+c)/3.0)*(a-(a+b+c)/3.0)+(b-(a+b+c)/3.0)*(b-(a+b+c)/3.0)+(c-(a+b+c)/3.0)*(c-(a+b+c)/3.0)
)
3.直接插入1到6之间的随机数就行了
insert into tt7 (a,b,c)values (
ceiling(rand(checksum(newid()))*6),
ceiling(rand(checksum(newid()))*6),
ceiling(rand(checksum(newid()))*6))
需要多行数据的时候,循环执行就好了
计算列的数据类型就是你的表达式结果的数据类型。如果要指定与计算公式不同的类型,请用cast/convert函数进行类型转换:create table tb_person (
id int not null primary key,
name varchar(32),
birthday datetime,
cast(datediff(day,birthday,getdate())/365 as int) as age,
create table 资环.学生(学号 char(8) primary key, 院系 as convert(tinyint,substring(学号,3,2))persisted not NULL,
--foreign key references 资环.院系 (01=文学,02=资环,03=英语),
姓名 char(4) not null,
性别 char(2) check (性别='男'or 性别='女'),
生源 char(6),
状态 char(2) check (状态 in('正常','留级'))
)
给你贴出来了,,,你错的不是一个2个地方,,好多地方有错,,,
你建立的外键的那个地方,我注释掉了,,
就是foreign key references 资环.院系 (01=文学,02=资环,03=英语)
这句
01=文学,02=资环,03=英语
不知道你这是啥意思,,,,
首先字段名称规则规定,字段不能以数字开头,其次你的'文学'估计你的是字段内容,要加引号的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)