Obtaining Foreing Keys Dependences
Jan 6, 2006
I want to know how to obtain the relationships of foreing keys when they have diferent names in diferent tables using SQL querys from VB.net in SQL Server 2000.
Example:
Table Person
------------
IDPerson
Name
Address
Table Customer
--------------
IDCustomer
.
.
.
Table Employee
---------------
IDEmployee
.
.
.
The dependencies are:
IDPerson--->IDCustomer
IDPerson--->IDEmployee
View 2 Replies
ADVERTISEMENT
May 16, 2008
Pls let me know How I generate script for All primary keys and foreign keys in a table. Thereafter that can be used to add primary keys and foreign keys in another databse with same structure.
Also how I script default and other constraints of a table?
View 2 Replies
View Related
Dec 12, 2007
hi
I could not build a query using the system tables; where I can know how many foreing keys does a specific table has? I´m lost.
can somebody help me... thanks
View 4 Replies
View Related
Jul 20, 2005
I'm a beginner in using SQLServer and I 'm trying to bring a db Schemawritten for DB2 into SQLServer.My problem is this: using a tool to translate the script for creating theDB, I obtain the following code:ALTER TABLE PROJECT.RSURETTA ADD FOREIGN KEY(VOCE )REFERENCES PROJECT.RSANVOCE(VOCE ) ON DELETE SET NULL ON UPDATE NO ACTIONBut, when I try to run the script the system says:Incorrect syntax near the keyword 'SET'.Can I assign a null value to an other table with a reference?Thank youFede
View 2 Replies
View Related
Mar 14, 2006
Hi,
I want to replicate in the same Server 2 tables, first I test with the same data datbases in other Server but 1 table and all is ok , when I try to do the same in the production server occurs an error, Distibution Agent Error Details show me this: Could not drop object 'SER_CURRENCY' because it is referenced by a FOREIGN KEY constraint. Like I said first I run a test, in this test I check IDENTITY: YES (Not for replication), ENFORCE RELATIONSHIPS FOR REPLICATION is unchecked.
My scenario is:
- Windows XP, SQL Server 2000 Developer Edition sp4.
Please, I want to know other reason for this error. Thanks
- Neyver.
View 1 Replies
View Related
Oct 19, 2007
I´m wondering how to solve the following scenario with SSIS
I have a CITY table and a STATE table, I have to load a file with the information regarding to the CITY:
the state table is like this:
StateCode(PK) stateLegalCode stateName
============= ============== =========
1 01 Florida
the city table is like this:
citycode(PK) cityLegalCode cityname StateCode(FK)
============ ============= ======== =============
1 1001 Quakertown 1
the file has the following information
cityLegalCode cityName
============= ========
01-1001 Quakertown
...
how can I load the file into CITY table:
1-) with the file's cityLegalCode I have to split the string and if the two initial digits are 01 the registry must have 1 in the StateCode(FK).
how can I do something like that using SSIS???
thanks
View 3 Replies
View Related
Apr 11, 2006
Hello again,
I'm going through my tables and rewriting them so that I can create relationship-based constraints and create foreign keys among my tables. I didn't have a problem with a few of the tables but I seem to have come across a slightly confusing hiccup.
Here's the query for my Classes table:
Code:
CREATE TABLE Classes
(
class_id
INT
IDENTITY
PRIMARY KEY
NOT NULL,
teacher_id
INT
NOT NULL,
class_title
VARCHAR(50)
NOT NULL,
class_grade
SMALLINT
NOT NULL
DEFAULT 6,
class_tardies
SMALLINT
NOT NULL
DEFAULT 0,
class_absences
SMALLINT
NOT NULL
DEFAULT 0,
CONSTRAINT Teacher_instructs_ClassFKIndex1 FOREIGN KEY (teacher_id)
REFERENCES Users (user_id)
)
This statement runs without problems and I Create the relationship with my Users table just fine, having renamed it to teacher_id. I have a 1:n relationship between users and tables AND an n:m relationship because a user can be a student or a teacher, the difference is one field, user_type, which denotes what type of user a person is. In any case, the relationship that's 1:n from users to classes is that of the teacher instructing the class. The problem exists when I run my query for the intermediary table between the class and the gradebook:
Code:
CREATE TABLE Classes_have_Grades
(
class_id
INT
PRIMARY KEY
NOT NULL,
teacher_id
INT
NOT NULL,
grade_id
INT
NOT NULL,
CONSTRAINT Grades_for_ClassesFKIndex1 FOREIGN KEY (grade_id)
REFERENCES Grades (grade_id),
CONSTRAINT Classes_have_gradesFKIndex2 FOREIGN KEY (class_id, teacher_id)
REFERENCES Classes (class_id, teacher_id)
)
Query Analyzer spits out: Quote: Originally Posted by Query Analyzer There are no primary or candidate keys in the referenced table 'Classes' that match the referencing column list in the foreign key 'Classes_have_gradesFKIndex2'. Now, I know in SQL Server 2000 you can only have one primary key. Does that mean I can have a multi-columned Primary key (which is in fact what I would like) or does that mean that just one field can be a primary key and that a table can have only the one primary key?
In addition, what is a "candidate" key? Will making the other fields "Candidate" keys solve my problem?
Thank you for your assistance.
View 1 Replies
View Related
Jul 16, 2014
what the best practice is for creating indexes on columns that are foreign keys to the primary keys of other tables. For example:
[Schools] [Students]
---------------- -----------------
| SchoolId PK|<-. | StudentId PK|
| SchoolName | '--| SchoolId |
---------------- | StudentName |
-----------------
The foreign key above is as:
ALTER TABLE [Students] WITH CHECK ADD CONSTRAINT [FK_Students_Schools]
FOREIGN KEY([SchoolId]) REFERENCES [Schools] ([SchoolId])
What kind of index would ensure best performance for INSERTs/UPDATEs, so that SQL Server can most efficiently check the FK constraints? Would it be simply:
CREATE INDEX IX_Students_SchlId ON Students (SchoolId)
Or
CREATE INDEX IX_Students_SchlId ON Students (SchoolId, StudentId)
In other words, what's best practice for adding an index which best supports a Foreign Key constraint?
View 4 Replies
View Related
Jul 15, 2002
Can somebody explain to me how to best do inserts where you have primary keys and foreign keys.l'm battling.
Is there an article on primary keys/Pk ?
View 1 Replies
View Related
Nov 22, 2007
Hello!I have a table A with fields id,startdate and other fields. id and startdateare in the primary key.In the table B I want to introduce a Foreign key to field id of table A.Is this possible? If yes, which kind of key I have to build in table A?Thx in advance,Fritz
View 6 Replies
View Related
Jan 4, 2008
How can I Export Database with foreing Key and primary key.
Operation is that
SQL2005 Management Studio/Database/Tasks/Export Data
Before Version is SQL2000 we can Selected Copy Object and data between server and then Use Default Options click checked and Select Copy Index, Copy Foreing Primary key vs vs
But this options is not found in the SQL2005 Management Studio/Database/Tasks/Export Data wizard or I can't found it.
How can I export foreing Key and primary key with SQL2005 Management Studio/Database/Tasks/Export Data wizard.
Best Regards,
Athena.
View 1 Replies
View Related
Jul 23, 2007
Let's say I need to be able to dynamically retrieve the last record in a table (ChData) in order to be able to continuously monitor the flow of data. Since theoretically there is no such thing defined in SQL, let's say I have an index column - ChTimestamp - (which, for some odd reason, is a DOUBLE), which grows monotonically. Thus, I want the row with the largest ChTimestamp value. The data columns would be Ch0, Ch1, and so on. Let's also assume that for some reason I am limited to using the LabVIEW database connectivity toolkit and because of that, I don't have full use of the SELECT statement but I have to supply the table and column names for the "SELECT FROM " and only the WHERE and the like predicates can be freely specified (I don't know how freely). What would be an elegant query to achieve the desired result? Thanks!
Kamen
View 6 Replies
View Related
Mar 23, 2006
Hi,
I'm new to these forums (and to SQL Server), so please be gentle with me.
I am developing a process to obtain information on all our remote servers/databases, and store it in a single local database.
I'm after things like db size, last backup date, free drive space etc...the usual weekly statistics.
I've linked the remote servers to my local one, and have written a few simple procedures (which exist on the local server) to grab backup and file size information from the remote tables. The output is stored locally in tables which we can then query as necessary.
I am having difficulty obtaining the free drive space details.
I'm using :-
'exec <remote_server>.master.dbo.xp_fixeddrives' to get the info, but I cannot store the output in a table on the local server. (remote_server_name, date, drive_letter, space_mb)
I wish to avoid creating any objects on the remote servers if at all possible.
I really want to pass the remote server name into the procedure, and the output to be inserted into the table.
Many thanks
View 4 Replies
View Related
Aug 31, 2006
I need to obtain the path to the master DB in a Wise install script. I know that for SQL2K it is in the registry key:
HKLMSoftwareMicrosoftMSSQLServerSetup
It seems that a SQL2005 installation does not have the same default
directory.
Is there a way to query this from the server itself so I don't have to read the registry?
View 1 Replies
View Related
Jan 6, 2012
What is the query to get 2nd last record from a table on a specific note_id key?
This is the data I have:
Note_id ======From Date===== =======To Date======
892481====2010-07-27 00:00:00===2010-07-27 00:00:00.000
892481====2010-07-27 00:00:00===2010-07-27 23:36:30.063
892481====2010-11-01 00:00:00===2010-11-02 00:15:23.027
892481====2011-03-08 00:00:00===2011-03-08 13:18:37.873 <====== This is the result i want
892481====2011-04-21 00:00:00===2011-04-21 07:57:20.567
View 11 Replies
View Related
Jun 4, 2007
I'll be working on a web project that utilizes sql server 2005. Our web host will be providing the server however I'll need a version of Sql Server 2005 management studio to work with it.
I believe the studio software costs around $50 however the express edition software is free.
So my question is, is the express edition software compatible with the full version of sql server 2005 or only sql server 2005 express edition?
Thanks.
-Goalie35
View 1 Replies
View Related
Jul 23, 2005
How is it possible to tell which version of ADO is installed on an XP workstation?Thanks
View 1 Replies
View Related
Jul 23, 2005
In MS SQL 2000, I would like to obtain the timezone offset from UTC fora given date. For today's date, I can doDATEDIFF(ss,GETDATE(),GETUTCDATE()). However, the offset for a futuredate may not be the same as today because some countries go in DaylightSaving mode. Can you suggest a way to obtain the timezone offset forany given date?ThanksYash
View 3 Replies
View Related
Jul 23, 2005
Is there a way to query a SQL server such that it will return thecurrent counter value of a field that increments automatically (anidentity field)? Using a MAX query might not necessarily give you thecorrect information because it is possible that the high value recordswere deleted. I checked the system tables and none of them appear tohave what I need. I suppose it would be possible to maintain a tablethat lists all the incrementing columns, but ideally there would be away already built into SQL Server.Thanks.
View 3 Replies
View Related
Jul 5, 2007
Hi People
We want one trigger which captures the data as mentioned below.
Table Name
Date and Time
User
type
Mode of modification
TABLE_ABC
03/07/2007 12:00:04
XCSRaoa
Update
Procedure
TABLE_DEF
03/07/2007 12:00:34
XCSRaoa
Insert
Class Integration SSIS Package
TABLE_GHI
03/07/2007 12:01:04
XCSRaoa
Insert
Procedure
TABLE_GHI
03/07/2007 12:01:34
XCSRaoa
Update
XCSRaoa (Manual)
I am not sure about how to achieve the last column. I hope u understand what exactly is expected. The idea is that, one should be able to track how a particular table was manipulate; whether it was manipulated using procedure or SSIS package or manually.
Could someone help me achieving this?
Regards
Abhi
View 5 Replies
View Related
Oct 3, 2006
Hello,
By using DBCC Page I am able to exemine data entered to row and other changes related to the rows. What I want to know is; is it possible to find out (and how) which Login ID commited these change directly from pages or where do I need to look to find it out?
Any guidance is appreciated....
View 1 Replies
View Related
Aug 13, 2007
Hi,
I have recently been looking at a database and wondered if anyone can tell me what the advantages are supporting a unique collumn, which can essentially be seen as the primary key, with an identity seed integer primary key.
For example:
id [unique integer auto incremented primary key - not null],
ClientCode [unique index varchar - not null],
name [varchar null],
surname [varchar null]
isn't it just better to use ClientCode as the primary key straight of because when one references the above table, it can be done easier with the ClientCode since you dont have to do a lookup on the ClientCode everytime.
Regards
Mike
View 7 Replies
View Related
Oct 6, 2006
Hi All,I'm having a bit of a problem with a c# program which creates and index file/table. The number of records I need to process is around 3500, the main loop. Each of thoes records I need to look at a 2 text fields and create an entry in an index table for each valid word found in thoes fields. I call a stored proc to save the key word. So this stored proc get called numerous time per record.What seems to be happening is proceese about 400 main rcords the errors out with the following error message: {"Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached." }Has anyone had a similar problem? if so any suggestions on how to fix, I've been looking at this problem and recoding for the last 4 days! I need some help! Using SQL Server 2000 & .net v1.1Thanks in advance Davej
View 1 Replies
View Related
Dec 31, 2006
Hi
I've been doing a website with ajax controls and I have tables that has foreign key relationships and hence the main page requires the data from the tables from the foreign keys stored in a separate table. Can anyone help me out with the proper way of querying the tables. Am not able to work out the way with the joins that SQL express provides.
Thanks
View 1 Replies
View Related
Feb 26, 2004
Can anyone tell me how I can obtain the number of records returned in a sqlDataReader recordset?
View 8 Replies
View Related
Apr 23, 2004
I'm hoping someone can shed some light on a reliable way to get Reporting Services if you don't have an MSDN subscription.
I have registered copies of SQL Server 2000 Developer and SQL Server 2000 Standard that I bought late last year.
I've had a backorder with MS Parts since January to get updated CDs with Reporting Services on them. Each month, the back order is pushed up another month. The disks are now due sometime in late May. I called the fulfillment center and the operator end didn't seem too enthusiastic about it coming in stock anytime soon.
All 3 versions (Developer, Standard, and Enterprise) are on a long back-order.
I thought I could get by temporarily by using the 90-day trial copy of Reporting Services, but I'm now concerned it might run out before I get my own non-trial version.
Isn't there a way for legit users to get a hold of this product? I'd be happy to download it, but it's not available unless I want to pay add'l money for an MSDN subscription.
_ANY_ suggestions or help appreciated.
Thanks.
dotnetFool
View 2 Replies
View Related
Dec 17, 2002
I have quite a few DTS's to work through while analysing current SQL databases for a client. Problem is I can't seem to find a way in SQL (Enterprise Manager) to print the contents of a DTS package. This is quite frustrating in that I have to go an "Design" the package, then click on the properties for each step and copy and paste the contents into Notepad/Wordpad. Surely Microsoft have something to ease the pain?
If anyone can help me on this one, I would be extremely grateful.
View 4 Replies
View Related
Apr 9, 2003
I need to lock a table in SQL Server. The reason is that I need to insert a value into an identity column (rather than just taking the next sequence number). I have a program that:
1. Sets identity insert on
2. Inserts into the table
3. Sets identity insert off
The problem is that I believe I should lock the table before I turn identity insert on (otherwise, other transactions will fail). I need to ensure that no other operations will take place on the table while I am doing all three of these steps.
I believe I can set the isolation level, but I cannot find any way to establish the lock without executing the update statement itself - which is a nanosecond too late to prevent another user from getting an error.
View 6 Replies
View Related
Nov 10, 1998
I've been having some strange problems lately upon connecting to SQL Server via the Enterprise Manager, or via MS Access. The response time is MUCH slower than usual. The only change I'm aware of is that additional drives were added to the server.
At any rate, when logging in to Access my login (not my query) times out. I get SQL State: S1T00; SQL Server Error: 0; MS ODBC SQL Server Driver: Timeout Expired.
I'm not sure where to begin to troubleshoot this. The version of SQL Server ODBC driver I have is 2.65.0252. Perhaps this one is corrupt. How would I ascertain what the latest version is? And, if it's appropriate to replace it, how do I go about it? Is it a simple overwrite of the file?
I'm using SQL Server 6.5 SP2 on NT 4.0.
Thanks,
Lisa
View 1 Replies
View Related
Jul 20, 2005
Dear GroupSorry for posting this here. I'm desperate for a solution to thisproblem and thought some of you might have come across it with .NETand SQL Server.Let's assume I've the following code:Private Sub Button4_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button4.ClickDim sqlConnection As New System.Data.SqlClient.SqlConnectionsqlConnection.ConnectionString = "workstation id=THEINTREPIDFOX;packetsize=4096;user id=sa;data source=""(local)"";p" & _"ersist security info=False;initial catalog=TestDB"sqlConnection.Open()sqlConnection.Close()sqlConnection = NothingEnd SubWhen I click 100 times on the button the page finally times out with:Timeout expired. The timeout period elapsed prior to obtaining aconnection from the pool. This may have occurred because all pooledconnections were in use and max pool size was reached.Of course I could increase the max pool size but this isn't thesolution to this problem. I wonder what's wrong with my code?According to MSDN, if the connection is closed it's released back intothe pool. Also tried to dispose but nothing helps. It looks like thatit keeps connections and doesn't release them. I'm grateful for anyhints, ideas, suggestions on this problem as I'm very desperate tosolve this.Thanks very much for your time & efforts!Martin
View 5 Replies
View Related
Aug 12, 2006
Hi All,
I really need some help here! I have spent the last few days upgrading a clients system to SQL 2005, part of which involved upgrading their sales people's laptops to Sql 2005 Express and setting up Merge Replication. I have configured the Server to use Web Synchronisation, and have tested that the replisapi.dll?diag all works ok and it does.
I am running into problems now with getting the laptops to synchronise. I have set up the Replication task, and am getting an error when I run the Wndows Synchroniser:
====================
The schema script '\PTC42ParklandsWebsiteV2ftpPTC42_PARKLANDS_PARKLANDS20060812131209' could not be propagated to the subscriber.
The process could not connect to FTP site 'mail.parklands.net' using port 21.
A connection with the server could not be established
==============
I have tested independantly connecting to the FTP server using Windows explorer and it works fine using the same username and password. I am at a loss here!!! I am going in circles looking for help too as there doesnt seem to be much info on this in SQL 2005 yet. I have re-read all the books online articles for Replication, Replication in SQL 2005 Express, and also gone back & reset up the Server & the Client several times - with no luck!
The client needs to get these sales guys laptops back ASAP and I am starting to really stress out here!! (can you tell I havent had much sleep in the last few days??) Any help would be so wonderfully apreciated!!!
Thanks so very much,
Catherine
View 1 Replies
View Related
Apr 29, 2008
Is there any way to get the new identity values created after an OLE DB Destination has finished its inserts?
Basically my problem is this...
My source database has its primary and foreign key columns as a GUID datatype. In my conversion, my destination database will be using INT (identity) columns for primary/foreign keys. How do I propagate the foreign key relationships to the destination database in an SSIS package? So obviously I can use an OLE DB Destination to generate the data with identities for the parent table, but after that I am stuck in how to create the relationships for the child tables.
I know how to do this in TSQL fairly easily (cursor or temp tables), but it doesn't seem so simple in SSIS.
thanks in advance.
View 9 Replies
View Related
Nov 27, 2007
Hi,
I want to be able to spot when the same employee name gets added to my grid. This is to ensure that I cannot not have the same firstname and lastname (i.e. cannot have 2 John Smiths).
It is kind of like spoting for duplicates but they are not PKs. I was hoping if there was a way you could identify the the feild values on the "inserting" event of the datasource so I could put some logic in. The reason for placing it there is because we have the e.cancel = true command.
Thanks in advance,
Jon
View 5 Replies
View Related