A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李玮 中级黑马   /  2012-5-27 10:35  /  3327 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 李玮 于 2012-5-31 17:48 编辑

怎么在sql2005的新建查询上设置主键啊 ,看了自己记得笔记,就看到primary    primarykey()什么的,不明确求大神解释,教导,解决了一定完善笔记

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

9 个回复

倒序浏览
如: create table test
(
id int not  null primary key,
name nvarchar(20)
)
这个就是把id设为主键

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

回复 使用道具 举报
create table test
(
t_id int not  null primary key,  //t_id字段名称, int字段数据类型, not  null指定字段是否可以是空值,primary key设置当前字段为主键
t_name varchar(10)
)
SQL Server有可视化操作,很简单的

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

回复 使用道具 举报
在管理其中打开表  在列上右键 设置主键 或者使用语句 primary key(Fnumber)); 一般是 int 和uniqueidentifier类型做主键(guid)

create table T_Employee(Fnumber varchar(10)not null,Fname Nvarchar(20) null,Fage int null,Fsalary numeric(10,2)null,

用 primary key(Fnumber));设置Fnumber做主键  

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

回复 使用道具 举报
朱亮辉 发表于 2012-5-27 12:06
create table test
(
t_id int not  null primary key,  //t_id字段名称, int字段数据类型, not  null指 ...

:) 受教了 我好想 把 空格丢了 key前面的 0..0

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

回复 使用道具 举报
喻健 发表于 2012-5-27 11:34
如: create table test
(
id int not  null primary key,

谢啦:lol  你最早发现的 给力
回复 使用道具 举报
我以前也不是很清楚 怎样用代码写主键 现在是受教了 嘿嘿!!Create Table T_Person(int ID not Null primary key,。。。)哦 现在还有个外键 嘿嘿
create Table T_Person(ID int foreign key references primary(ID)  )   嘿嘿  !

评分

参与人数 1技术分 +1 收起 理由
郑文 + 1

查看全部评分

回复 使用道具 举报
刘豪 中级黑马 2012-5-29 17:44:21
8#
建议你找一本数据库管理系统的书看,你的基础太不牢靠了,萨师宣的书不错。
回复 使用道具 举报
用可视化操作好简单的,也可以写sql语句:create table test
(
t_id int not  null primary key,  //t_id字段名称, int字段数据类型, not  null指 ...

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
primary key是给一张表建立主键,需要注意的是一张表只能有一个主键,主键是唯一的不能重复,在程序中操作数据的时候我们可以使用主键来操作,这样更准确

评分

参与人数 1技术分 +1 收起 理由
宋天琪 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马