|
I want to create a table in which only one row should be insert.
If any user want to insert another row in that table then it is not possible...
Please just reply query...
|
|
|
|
|
Try using something like:
select count(*) from MyTable
if (count = 0) then
do insert
else
fail
|
|
|
|
|
Why would you need a table with just 1 row?
|
|
|
|
|
Try an INSTEAD OF TRIGGER
|
|
|
|
|
Make sure the Primary Key can only contain 1 value using a check constraint:
ALTER TABLE [dbo].[MyTable] WITH CHECK ADD CONSTRAINT [CK_OneRow] CHECK (([Id]=(1)))
|
|
|
|
|
Michael Potter wrote: Make sure the Primary Key can only contain 1 value using a check constraint:
ALTER TABLE [dbo].[MyTable] WITH CHECK ADD CONSTRAINT [CK_OneRow] CHECK (([Id]=(1)))
That is a very cool way to solve a very strange request. I'll give it a 5.
|
|
|
|
|
Super solution but can't be replicated in other databases like oracle.
Identity is a near equivalent to rowid concept in Oracle but its a dynamic value i.e not a sequence generator . Hence may be Only possible in sql server.
Regards
Sreeni
www.sreenivaskandakuru.com
|
|
|
|
|
If you change the start value of the identity seed (I'm pretty sure this can be done) and truncate the table the hard coded 1 would fail mind you it is a silly request in the first place and I suspect the OP does not even know what you are talking about.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It may not be as useless as it first appears. I have used this method to hold global variables that are used by more than one application.
|
|
|
|
|
It'd be easier to create a view and be done with it;
CREATE VIEW GlobalSettingsTable AS
SELECT 1 AS ColumnName,
2 AS Nanana,
'C:\Program Files'
|
|
|
|
|
Yes - if your values are constants.
|
|
|
|
|
No, also for dynamic values; you can put sub-selects in there, or even calls to managed code
|
|
|
|
|
Don't get me wrong, I did not consider it useless (even in this idiotic context) just being a pedantic bastard.
Never underestimate the power of human stupidity
RAH
|
|
|
|