易截截图软件、单文件、免安装、纯绿色、仅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 Server中使用NewID()方法产生随机集

在SQL Server中使用NewID()方法产生随机集
例如考试系统中的随机出题
刚开始想到的是Random类
但是Random效率有点低
后来想到了在数据库里的newid()
于是采用了下边方法:
select top 5 * from tablename order by newid()
在此标记一下 ......

Sql Server 2005 中的同义词与复制

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

解决SQL Server里sp_helptext输出格式错行问题

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 ......

PL/SQL实例分析

PL/SQL实例分析
第五章
1、PL/SQL实例分析
1)在【SQLPlus Worksheet】中直接执行如下SQL代码完成上述操作。(创建表)
―――――――――――――――――――――――――――――――

CREATE TABLE "SCOTT"."TESTTABLE" ("RECORDNUMBER" NUMBER(4) NOT NULL, "CURRENTDATE" DATE NOT NULL)
TABLESPACE "SYSTEM ......

常用SQL语句集合

1、说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)
法一:select * into b from a where 1 <>1
法二:select top 0 * into b from a
2、说明:拷贝表(拷贝数据,源表名:a 目标表名:b) (Access可用)
insert into b(a, b, c) select d,e,f from b;
3、说明:跨数据库之间表的拷贝(具体数据使用 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号