Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL SERVER 2008

SQL SERVER 2008

Scheduled Pinned Locked Moved Database
databasesql-serversysadmin
13 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M M T H Danish

    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...

    C Offline
    C Offline
    Corporal Agarn
    wrote on last edited by
    #4

    Try an INSTEAD OF TRIGGER

    1 Reply Last reply
    0
    • M M T H Danish

      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...

      M Offline
      M Offline
      Michael Potter
      wrote on last edited by
      #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)))

      D M 2 Replies Last reply
      0
      • M Michael Potter

        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)))

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #6

        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.

        S 1 Reply Last reply
        0
        • M Michael Potter

          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)))

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #7

          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

          M 1 Reply Last reply
          0
          • M Mycroft Holmes

            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

            M Offline
            M Offline
            Michael Potter
            wrote on last edited by
            #8

            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.

            L M 2 Replies Last reply
            0
            • M Michael Potter

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #9

              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![^]

              M 1 Reply Last reply
              0
              • M Michael Potter

                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.

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #10

                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

                1 Reply Last reply
                0
                • L Lost User

                  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![^]

                  M Offline
                  M Offline
                  Michael Potter
                  wrote on last edited by
                  #11

                  Yes - if your values are constants.

                  L 1 Reply Last reply
                  0
                  • M Michael Potter

                    Yes - if your values are constants.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    No, also for dynamic values; you can put sub-selects in there, or even calls to managed code :)

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

                    1 Reply Last reply
                    0
                    • D David Mujica

                      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.

                      S Offline
                      S Offline
                      Srini Sydney
                      wrote on last edited by
                      #13

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups