SQL SERVER 2008
-
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 an INSTEAD OF TRIGGER
-
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...
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)))
-
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.
-
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)))
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 :laugh: 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
-
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 :laugh: 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 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, -- You can't touch this
2 AS Nanana,
'C:\Program Files'Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]
-
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.
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
-
It'd be easier to create a view and be done with it;
CREATE VIEW GlobalSettingsTable AS
SELECT 1 AS ColumnName, -- You can't touch this
2 AS Nanana,
'C:\Program Files'Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]
Yes - if your values are constants.
-
Yes - if your values are constants.
-
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