sql server 定义主键
drop table father;
create table father(
id int identity(1,1) primary key,
name varchar(20) not null,
age int not null
)
drop table mother;
create table mother(
id int identity(1,1),
name varchar(20) not null,
age int not null,
husband int not null
)
alter table mother
add constraint FK_ID foreign key(husband) references father(id)
如果 在father中没能定义主键,
drop table father;
create table father(
id int identity(1,1), (未定义 primary key)
name varchar(20) not null,
age int not null
)
则会报如下异常:
在被引用表 'father' 中没有与外键 'FK_ID' 的引用列的列表匹配的主键或候选键
相关文档:
请教大家一个有关SQL交驻报表查询问题,欢迎各位指教!
我想把图1的使用信息,使用SQL语句,实现如图2的结果。
表名
序号
字段名
a
1
c
a
2
d
a
3
e
a
4
f
a
5
g
b
1
h
b
2
i
b
3
j
b
4
k
b
5
l
c
1
m
c
2
n
c
3
o
c
4
p
c
5
q
图1
表名
序号
1
2
3
4
5
......
use Master
go
if object_id('SP_SQL') is not null
drop proc SP_SQL
go
create proc [dbo].[SP_SQL](@ObjectName sysname)
as
set nocount on ;
declare @Print varchar(max)
if exists(select 1 from syscomments where ID=objec ......
4.数据类型转换函数
●隐式转换
赋值时可进行的隐式转换有
VARCHAR2或CHAR —〉NUMBER
VARCHAR2或CHAR —〉DATE
NUMBER —〉VARCHAR ......
...
)
用到的功能有:
1.如果我更改了学生的学号,我希望他的借书记录仍然与这个学生相关(也就是同时更改借书记录表的学号);
2.如果该学生已经 ......