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. Default values in microsoft Sql Server

Default values in microsoft Sql Server

Scheduled Pinned Locked Moved Database
databasesql-serversysadminalgorithmsquestion
4 Posts 3 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.
  • N Offline
    N Offline
    Neophyte30
    wrote on last edited by
    #1

    I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in

    User_id first_name last_name some_data
    1 Test User 1 test

    I was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al

    S S 2 Replies Last reply
    0
    • N Neophyte30

      I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in

      User_id first_name last_name some_data
      1 Test User 1 test

      I was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al

      S Offline
      S Offline
      SimulationofSai
      wrote on last edited by
      #2

      Set your default value to something like 'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) or for more randomness 'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) + CAST(DATEPART(ms, GETDATE()) AS VARCHAR) You'll get fairly random data, not entirely unique though.

      SG Cause is effect concealed. Effect is cause revealed.

      N 1 Reply Last reply
      0
      • S SimulationofSai

        Set your default value to something like 'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) or for more randomness 'Test' + CAST(DATEPART(second, GETDATE()) AS VARCHAR) + CAST(DATEPART(ms, GETDATE()) AS VARCHAR) You'll get fairly random data, not entirely unique though.

        SG Cause is effect concealed. Effect is cause revealed.

        N Offline
        N Offline
        Neophyte30
        wrote on last edited by
        #3

        Thanks - perfect for what I need! :-D

        1 Reply Last reply
        0
        • N Neophyte30

          I would like to specify a default value for a column that increments along with the row number/identity column. i.e. Insert tbl_User (some_data) VALUES (test) resulting in

          User_id first_name last_name some_data
          1 Test User 1 test

          I was sure there was something like @@row_number, but searching on msdn/google has turned up nothing useful so far... Any suggestions? Thanks, Al

          S Offline
          S Offline
          sonia sardana
          wrote on last edited by
          #4

          use sonia create table stud(roll int identity(10,2),name varchar) insert into stud values('A') insert into stud values('B') select * from stud **IDENTITY(10,2) --> 10 is the initial value 2 is the number by which the value is to be incremented. U can also decrement the value.

          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