Showing posts with label entering. Show all posts
Showing posts with label entering. Show all posts

Sunday, March 11, 2012

Check data Availbility between two table in Sqlserver 2005 using C#

I have Two table.One is MainTable and other is Temporary table.Both have Same Field

Before entering data into main table I want to check weather these data's are already there or not.

Here i am checking only three column of temporary table to the MainTable.

INSERT INTO MailTable(A, B, C)
SELECT (A, B, C) FROM TemporaryTable WHERE TemporaryTable.A NOT IN (SELECT A FROM MailTable)

|||

Thank you Thank you Thank you Thank you Very Much

Thursday, March 8, 2012

check constraint

Hi ,
Could a check constraint check for another column i.e u
need to ensure that either ColA OR ColB must NOT be null
when entering the information into the table ?
or a trigger is a better solution ?
thks & rdgs
You can use a table-level CHECK constraint to enforce this rule. For
example:
CREATE TABLE MyTable
(
ColA int NULL,
ColB int NULL,
ColC int NULL,
CONSTRAINT CK_ColC
CHECK (ColA IS NOT NULL OR ColB IS NOT NULL)
)
Hope this helps.
Dan Guzman
SQL Server MVP
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs
|||Sure, you could do it with a check constraint... either of the following
syntax:
CREATE TABLE #foo(A INT,
B INT,
CHECK (A IS NOT NULL OR B IS NOT NULL))
...or...
CREATE TABLE #foo(A INT,
B INT)
ALTER TABLE #foo
ADD CONSTRAINT A_B_NotNULL CHECK (A IS NOT NULL OR B IS NOT NULL)
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs
|||The reason a check constraint is the better choice (even though you could do
the same thing in a trigger), is that the Check constraint works faster..
In general, if you can get something done in a check constraint, do it
there... Only when check constraints can't do the job do we go into
triggers.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs

check constraint

Hi ,
Could a check constraint check for another column i.e u
need to ensure that either ColA OR ColB must NOT be null
when entering the information into the table ?
or a trigger is a better solution ?
thks & rdgsYou can use a table-level CHECK constraint to enforce this rule. For
example:
CREATE TABLE MyTable
(
ColA int NULL,
ColB int NULL,
ColC int NULL,
CONSTRAINT CK_ColC
CHECK (ColA IS NOT NULL OR ColB IS NOT NULL)
)
--
Hope this helps.
Dan Guzman
SQL Server MVP
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs|||Sure, you could do it with a check constraint... either of the following
syntax:
CREATE TABLE #foo(A INT,
B INT,
CHECK (A IS NOT NULL OR B IS NOT NULL))
...or...
CREATE TABLE #foo(A INT,
B INT)
ALTER TABLE #foo
ADD CONSTRAINT A_B_NotNULL CHECK (A IS NOT NULL OR B IS NOT NULL)
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs|||>--Original Message--
>Hi ,
> Could a check constraint check for another column i.e u
>need to ensure that either ColA OR ColB must NOT be null
>when entering the information into the table ?
> or a trigger is a better solution ?
>thks & rdgs
>.
>|||The reason a check constraint is the better choice (even though you could do
the same thing in a trigger), is that the Check constraint works faster..
In general, if you can get something done in a check constraint, do it
there... Only when check constraints can't do the job do we go into
triggers.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs

check constraint

Hi ,
Could a check constraint check for another column i.e u
need to ensure that either ColA OR ColB must NOT be null
when entering the information into the table ?
or a trigger is a better solution ?
thks & rdgsYou can use a table-level CHECK constraint to enforce this rule. For
example:
CREATE TABLE MyTable
(
ColA int NULL,
ColB int NULL,
ColC int NULL,
CONSTRAINT CK_ColC
CHECK (ColA IS NOT NULL OR ColB IS NOT NULL)
)
Hope this helps.
Dan Guzman
SQL Server MVP
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs|||Sure, you could do it with a check constraint... either of the following
syntax:
CREATE TABLE #foo(A INT,
B INT,
CHECK (A IS NOT NULL OR B IS NOT NULL))
...or...
CREATE TABLE #foo(A INT,
B INT)
ALTER TABLE #foo
ADD CONSTRAINT A_B_NotNULL CHECK (A IS NOT NULL OR B IS NOT NULL)
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs|||The reason a check constraint is the better choice (even though you could do
the same thing in a trigger), is that the Check constraint works faster..
In general, if you can get something done in a check constraint, do it
there... Only when check constraints can't do the job do we go into
triggers.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"maxzsim" <anonymous@.discussions.microsoft.com> wrote in message
news:bdd801c48977$13af8500$a401280a@.phx.gbl...
> Hi ,
> Could a check constraint check for another column i.e u
> need to ensure that either ColA OR ColB must NOT be null
> when entering the information into the table ?
> or a trigger is a better solution ?
> thks & rdgs