Showing posts with label foreign. Show all posts
Showing posts with label foreign. Show all posts

Sunday, 11 March 2012

Connect at only One port

When connecting to sql 2000 Enterprise manager opens multiple ports.
For example
Proto Local Address Foreign Address State
TCP 192.168.7.12:1433 192.168.7.12:3275 ESTABLISHED
TCP 192.168.7.12:1433 192.168.7.12:3634 ESTABLISHED
TCP 192.168.7.12:3634 192.168.7.12:1433 ESTABLISHED
How can I force sql to connect only at 1433 or other single port. I facts
is there such posibility?
Hi -
If you analyze the entries in the SQL Server error log file, you can verify
that the instance of SQL Server is listening on the correct IP address and on
the correct port. By default, a default instance of SQL Server listens on the
port 1433. You can also use Server Network Utility to verify the protocol
settings for SQL Server and to change the properties in SQL Server, including
the protocols that can connect to SQL Server and the ports that can be used.
For more information about using Server Network Utility, see the "SQL Server
Network Utility" topic in SQL Server Books Online.
Sometimes, SQL Server 2000 may not bind to port 1433 or any other specified
port. This problem may occur if the port is being used by another application
or if you are trying to connect by using an IP address that is not correct.
Therefore, the TCP/IP connections to SQL Server may not be successful and you
may receive the following error message in the SQL Server error log file:
2001-11-14 15:49:14.12 server SuperSocket Info: Bind failed on TCP port 1433.
Please check the below link :
http://support.microsoft.com/default.aspx?kbid=307197
Let me know if it helps you.
"Radin" wrote:

> When connecting to sql 2000 Enterprise manager opens multiple ports.
> For example
> Proto Local Address Foreign Address State
> TCP 192.168.7.12:1433 192.168.7.12:3275 ESTABLISHED
> TCP 192.168.7.12:1433 192.168.7.12:3634 ESTABLISHED
> TCP 192.168.7.12:3634 192.168.7.12:1433 ESTABLISHED
> How can I force sql to connect only at 1433 or other single port. I facts
> is there such posibility?
>

Connect at only One port

When connecting to sql 2000 Enterprise manager opens multiple ports.
For example
Proto Local Address Foreign Address State
TCP 192.168.7.12:1433 192.168.7.12:3275 ESTABLISHED
TCP 192.168.7.12:1433 192.168.7.12:3634 ESTABLISHED
TCP 192.168.7.12:3634 192.168.7.12:1433 ESTABLISHED
How can I force sql to connect only at 1433 or other single port. I facts
is there such posibility?Hi -
If you analyze the entries in the SQL Server error log file, you can verify
that the instance of SQL Server is listening on the correct IP address and o
n
the correct port. By default, a default instance of SQL Server listens on th
e
port 1433. You can also use Server Network Utility to verify the protocol
settings for SQL Server and to change the properties in SQL Server, includin
g
the protocols that can connect to SQL Server and the ports that can be used.
For more information about using Server Network Utility, see the "SQL Server
Network Utility" topic in SQL Server Books Online.
Sometimes, SQL Server 2000 may not bind to port 1433 or any other specified
port. This problem may occur if the port is being used by another applicatio
n
or if you are trying to connect by using an IP address that is not correct.
Therefore, the TCP/IP connections to SQL Server may not be successful and yo
u
may receive the following error message in the SQL Server error log file:
2001-11-14 15:49:14.12 server SuperSocket Info: Bind failed on TCP port 1433
.
Please check the below link :
http://support.microsoft.com/default.aspx?kbid=307197
Let me know if it helps you.
"Radin" wrote:

> When connecting to sql 2000 Enterprise manager opens multiple ports.
> For example
> Proto Local Address Foreign Address State
> TCP 192.168.7.12:1433 192.168.7.12:3275 ESTABLISHED
> TCP 192.168.7.12:1433 192.168.7.12:3634 ESTABLISHED
> TCP 192.168.7.12:3634 192.168.7.12:1433 ESTABLISHED
> How can I force sql to connect only at 1433 or other single port. I facts
> is there such posibility?
>

Wednesday, 7 March 2012

Confused with primary keys and foreign keys

Hi, I am currently doing a database project for my company. The database contains 5 tables inside, let's say A,B,C,D,E. The primary key of table A is referenced by all other tables. If an instance is created in other tables except in table A, it means that the foreign keys are not null. However, if an instance is created in table A, it doesn't necessarily mean that the primary key of that particular instance must be referenced by another instance in other tables. In other words, the foreign keys in other tables have null value.

Now, the question is how can I display this primary key in table A together with primary keys of other tables since some of them may not even exist yet? By displaying all the primary keys, I can therefore check that the primary keys in other tables still don't exist and with this, I can input a value to it.

P.S. I am connecting the database with VB 2005 Express Edition and I always get blank value when I tried to retrieve the value.

Thank you very much for the help

Foreign Key:

Is the advanced check constraint which will check the set of values from the another table. The another/reference table is called parent/master table & the current table is called child/detailed table. The Master table which holds the set of value should be not null unique. (you can’t have the more than one Parent for single Child). But your child table column can hold NULL value (which is not yet born)

Primary key:

Is the table levelconstraint which will ensure your table columns have a unique & not null values.

Display the Parent & child values (which is not yet born):

You have to use OUTER JOIN to achieve this. If you post more information we can provide the rite information to you.

|||

The basic problem is that IF there is not a row in the Child table (table with FK), or there is a row, but its FK value is NULL, there is no way to 'connect' the row to the Parent table (table with PK).

It is possible to 'simulate' the missing rows by using a LEFT JOIN, and referring to the Parent table first.

Try out this sample code to see how to combine tables where both tables have matching values, and also where one table is missing a FK value from the other table.

Code Snippet


--***********************************
--Problem: Demonstrate PK-FK JOINS


CREATE TABLE Parent
( RowID int IDENTITY PRIMARY KEY,
MyValue varchar(20)
)
GO


CREATE TABLE Child
( RowID int IDENTITY PRIMARY KEY,
ParentID int REFERENCES Parent(Rowid),
MyValue varchar(20)
)
GO


SET NOCOUNT ON


INSERT INTO Parent VALUES ( 'Parent1' )
INSERT INTO Parent VALUES ( 'Parent2' )
INSERT INTO Parent VALUES ( 'Parent3' )
INSERT INTO CHILD VALUES ( 2, 'Child1' )
INSERT INTO CHILD VALUES ( 3, 'Child2' )
INSERT INTO CHILD VALUES ( 2, 'Child3' )
INSERT INTO CHILD VALUES ( NULL, 'Child4' )


-- To find ONLY Parents AND their Children
SELECT
ParentID = p.RowID,
ParentValue = p.MyValue,
ChildID = c.RowID,
ChildValue = c.MyValue
FROM Parent p
JOIN Child c
ON p.RowID = c.ParentID


-- To find All Parents and Children (if Any)
SELECT
ParentID = p.RowID,
ParentValue = p.MyValue,
ChildID = c.RowID,
ChildValue = c.MyValue
FROM Parent p
LEFT JOIN Child c
ON p.RowID = c.ParentID


-- To find Parents without Children
SELECT
ParentID = p.RowID,
ParentValue = p.MyValue,
ChildID = c.RowID,
ChildValue = c.MyValue
FROM Parent p
LEFT JOIN Child c
ON p.RowID = c.ParentID
WHERE c.ParentID IS NULL


-- To find Children without Parents (Orphans)
SELECT
ParentID = p.RowID,
ParentValue = p.MyValue,
ChildID = c.RowID,
ChildValue = c.MyValue
FROM Parent p
RIGHT JOIN Child c
ON p.RowID = c.ParentID
WHERE c.ParentID IS NULL


DROP TABLE Child
DROP TABLE Parent

|||Thanks for both your suggestions, but I don't have any idea how to perform LEFT JOIN on 5 tables. Can you gimme some idea on this? Thanks..|||

Manivannan.D.Sekaran wrote:

Foreign Key:

Is the advanced check constraint which will check the set of values from the another table. The another/reference table is called parent/master table & the current table is called child/detailed table. The Master table which holds the set of value should be not null unique. (you can’t have the more than one Parent for single Child). But your child table column can hold NULL value (which is not yet born)

Primary key:

Is the table level constraint which will ensure your table columns have a unique & not null values.

Display the Parent & child values (which is not yet born):

You have to use OUTER JOIN to achieve this. If you post more information we can provide the rite information to you.

The child values are actually not null, they are only not yet born. However, I need to display both the parent table which already has a child and which has no child at all. I will try to use OUTER JOIN in the code and see how the result will be. Thanks a lot.

Friday, 24 February 2012

Conflict Error

Hi All;

I am getting ;

INSERT statement conflicted with TABLE FOREIGN KEY constraint 'FK_ChecklistCases_ChecklistFGroups'. The conflict occurred in database 'Test', table 'ChecklistFGroups'. The statement has been terminated.

but it seems to be no error can you help me please I can send you the related part of database

thank youit says you are violating the forien key constriant..its always a good idea to check if the data exists before you insert..

hth

conflict between (cascade) DELETE Trigger and Foreign Key Constrain

I'm trying to create relational database with some triggers in SQL Server 7.0, but it doesn't work as expected. Let's say that I have 'Office' database with two tables, 'Users' and 'UserRights' (userRights table should have much more rights, but that's not relevant for this problem):

CREATE TABLE [Users] (
[FS_Username] [nvarchar] (8) NOT NULL ,
[FS_Password] [nvarchar] (32) NOT NULL ,
CONSTRAINT [PK_Users] PRIMARY KEY NONCLUSTERED
(
[FS_Username]
) ON [PRIMARY]
) ON [PRIMARY]
GO

CREATE TABLE [UserRights] (
[FS_Username] [nvarchar] (8) NOT NULL ,
[FI_UserType] [int] NOT NULL CONSTRAINT [DF_UserRights_FI_UserType] DEFAULT (1),
[FI_AllowLogin] [int] NOT NULL CONSTRAINT [DF_UserRights_FI_AllowLogin] DEFAULT (1),
CONSTRAINT [PK_UserRights] PRIMARY KEY NONCLUSTERED
(
[FS_Username]
) ON [PRIMARY] ,
CONSTRAINT [FK_UserRights_Users] FOREIGN KEY
(
[FS_Username]
) REFERENCES [Users] (
[FS_Username]
)
) ON [PRIMARY]
GO

Foreign Key CONSTRAIN above is created by adding both tables to the diagram and defining relationship between these two tables FS_Username field, where 'Enable relationship for INSERT and UPDATE' option is turned ON. You can easily see this if you create diagram youself and insert these two tables in it.
Next to this, I created two triggers that should handle inserting/deleting rows in UserRights table as consequence of inserting/deleting rows in Users table:

CREATE TRIGGER InsertUserRights ON Users
FOR INSERT
AS
BEGIN
INSERT INTO UserRights (FS_Username) (SELECT FS_Username FROM Inserted)
END

CREATE TRIGGER DeleteUserRights ON Users
FOR DELETE
AS
BEGIN
DELETE UserRights WHERE FS_Username IN
(SELECT FS_Username FROM Users)
END

Now, when (manually) I insert row in Users table, UserRights table gets updated accordingly. HOWEVER, when I try to delete one or more entries from Users table, I get error report. For example, if you try to execute following two commands:

Insert Into Users (FS_Username, FS_Password) VALUES ('John', 's')

Delete from Users

... first command will succede, but second one will fail with message:

DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_UserRights_Users'. The conflict occurred in database 'Office', table 'UserRights', column 'FS_Username'.
The statement has been terminated.

Does anyone know how to resolve this problem without loosing constrains and triggers ? (If I turn off 'Enable relationship for INSERT and UPDATE' option for relationship, things will work fine, but than I can make inconsistent data in UserRights table).

tnx a lot,
DejanSorry, second trigger should be:

CREATE TRIGGER DeleteUserRights ON Users
FOR DELETE
AS
BEGIN
DELETE UserRights WHERE FS_Username IN
(SELECT FS_Username FROM deleted)
END

This is just the correct trigger, it doesn't solve the problem in hand...

Dejan