当前位置: 代码迷 >> Sql Server >> 用SQL语句建数据表时,如何样让某列设为主键的?命苦啊
  详细解决方案

用SQL语句建数据表时,如何样让某列设为主键的?命苦啊

热度:38   发布时间:2016-04-27 20:51:54.0
用SQL语句建数据表时,怎么样让某列设为主键的??????命苦啊,求助啊!!!
简单的问题,一直困扰住我!!!!!

请大家帮帮我!!!!

TKS!

------解决方案--------------------
create table test(test1 int primary key)

primary key表示test1这个字段是主键
------解决方案--------------------
Create table t
(
id int primary key ,col varchar(5)

------解决方案--------------------
Create table t
(
id int primary key ,
col1 varchar(5),
col2 varchar(5)

alter table t add constraint fk_col foreign key (col1) references t2(col1)
------解决方案--------------------
借用一下楼上的数据
Create table t
(
id int primary key ,
col1 varchar(5),
col2 varchar(5)

alter table t add constraint pk_col primary key (id)

------解决方案--------------------
Create table t
(
id int ,
col1 varchar(5),
col2 varchar(5)
)primary key(id)
  相关解决方案