易截截图软件、单文件、免安装、纯绿色、仅160KB

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语法的存储过程

      一般用BCP在处理这个事情,但有时也需要一些特殊的处理,以下是生成表中的一些数据,带有where条件的选择生成数据,是我一个同事修改的,直接拿过来用了:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc proc_insert_where (@tablename varchar(256),@where varchar(256 ......

利用SQL移动硬盘文件

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_movefile]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_movefile]
GO
/*--移动服务器上的文件
 不借助 xp_cmdshell ,因为这个在大多数时候都被禁用了
--邹建 2004.08(引用请保留此信息)--*/
/*--调用示例 ......

Sql Server 2005 中的同义词与复制

在2005中有同义词与复制的概念
同义词的主要作用是:
        一:宿短对象的名称,减少工作人员书写的时间,提高效率。我们知道访问数据库一个对象的通常最全的对象名称是:服务器名称。数据库名称。架构名称。对象名称
        二:同步数据。 ......

循序渐进讲解SQL查询语句高级应用技巧

一、 简单查询
简单的Transact-SQL查询只包括选择列表、from子句和WHERE子句。它们分别说明所查询列、查询的
表或视图、以及搜索条件等。
例如,下面的语句查询testtable表中姓名为“张三”的nickname字段和email字段。
SELECT nickname,email
from testtable
WHERE name='张三'
 
(一) 选择 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号