MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 10th, 2004, 03:08 PM
bzborow1 bzborow1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 84 bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 17 h 51 m 9 sec
Reputation Power: 7
Access to SQL Server help...

Hi everyone,

I'm new to SQL Server, and i've got a mini project to convert an MS Access backend of a webapp to SQL Server 2000. I've been able to correct all the names//datatype errors, and upload data ok. My problem, however, is with relationships between tables.

Here's my problem:

If given two tables, TABLE A (1:many) TABLE B
the FK in TABLE B (from A) does not have to be entered, that is, it can be in table A or null.

Right now when I load my webpage, I can only insert a record into TABLE B if I fill that FK with data, but as a business rule this does not have to be entered.

I've been playing around with triggers to help fix this, but i'm a newbie to triggers...can anyone give me any pointers on how to write a triggers to handle this??

Thanks,

Bill

Reply With Quote
  #2  
Old May 10th, 2004, 03:48 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,745 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 39 m 51 sec
Reputation Power: 870
triggers not necessary

just make sure the FK in table B is declared NULL

then you will not have to enter a FK value if you don't want to
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old May 10th, 2004, 04:45 PM
bzborow1 bzborow1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 84 bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 17 h 51 m 9 sec
Reputation Power: 7
Yes, but what's getting me is that I have the field so it allows NULLS. But I still get this error:

Create Failed
An unexpected error has occurred.
Please contact your system administrator with the following information.
Error Number: -2147217900
Error Description: The record can't be added or changed. Referential integrity rules require a related record in table 'tblAttendants'.
Error Source: Microsoft OLE DB Provider for SQL Server

Reply With Quote
  #4  
Old May 10th, 2004, 05:01 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,745 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 39 m 51 sec
Reputation Power: 870
could you script the CREATE TABLE statements for me?

Reply With Quote
  #5  
Old May 12th, 2004, 12:23 AM
bzborow1 bzborow1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 84 bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 17 h 51 m 9 sec
Reputation Power: 7
Well I used the upsizing wizard to generate the tables, then ran the data transfer from the enterprise manager. But I can write up some scripts for sure. I have double-checked and the fields are set to allow nulls.

Reply With Quote
  #6  
Old May 12th, 2004, 12:37 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,745 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 39 m 51 sec
Reputation Power: 870
enterprise manager can generate the scripts for you

Reply With Quote
  #7  
Old May 12th, 2004, 09:40 AM
bzborow1 bzborow1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 84 bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level)bzborow1 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 17 h 51 m 9 sec
Reputation Power: 7
here is the script generated for the table in question...The items generating the error are Attendant1ID, Attendant2ID, Attendant3ID as they link to a parent table, but are not "required" fields.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblMiscItemEMSCards_FK01]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblMiscItemEMSCards] DROP CONSTRAINT tblMiscItemEMSCards_FK01
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblPCRs_FK10]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblPCRs] DROP CONSTRAINT tblPCRs_FK10
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblEMSCards]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblEMSCards]
GO

CREATE TABLE [dbo].[tblEMSCards] (
[CardID] [int] IDENTITY (1, 1) NOT NULL ,
[CardType] [nvarchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DispatcherID] [int] NULL ,
[CallOriginID] [int] NULL ,
[FirstRespGroupID] [int] NULL ,
[Attendant1ID] [int] NULL ,
[Attendant2ID] [int] NULL ,
[Attendant3ID] [int] NULL ,
[AreaID] [int] NULL ,
[PULocationID] [int] NULL ,
[DestinationID] [int] NULL ,
[ResponseToID] [int] NULL ,
[ResponseFromID] [int] NULL ,
[Unit1ID] [int] NULL ,
[Unit2ID] [int] NULL ,
[ScheduledCall] [bit] NOT NULL ,
[CardNum] [int] NULL ,
[Time] [datetime] NULL ,
[TimeOfCall] [datetime] NULL ,
[PreAlert] [datetime] NULL ,
[OnAir] [datetime] NULL ,
[TimeOfResponse] [datetime] NULL ,
[107Scene] [datetime] NULL ,
[PatientSide] [datetime] NULL ,
[DepartScene] [datetime] NULL ,
[107Destination] [datetime] NULL ,
[108Clear] [datetime] NULL ,
[BackAtBase] [datetime] NULL ,
[Date] [datetime] NULL ,
[UrbanRural] [nvarchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Specials] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FirstName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LastName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Sex] [nvarchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SHSP] [nvarchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[PULocation] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Destination] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ChiefComplaint] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LandLocation] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CallerName] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CallerNumber] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[OtherCallOrigin] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RelatedCardNumbers] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CreateUser] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CreateDate] [datetime] NULL ,
[LastUpdateUser] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LastUpdateDate] [datetime] NULL
) ON [PRIMARY]
GO

Reply With Quote
  #8  
Old June 8th, 2004, 09:29 AM
Hombre80 Hombre80 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 Hombre80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Moving the data from Access to SQL Server

Hi guy,
I need to be helped...I'm trying to get the data from Access to put in SQL Server but I have problem everytime.
Anybody know how can I do to resolve this problem.
I'm waiting your information!!!!
Thanks!!

Simo

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Access to SQL Server help...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway