Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Wednesday, March 28, 2012

How to assign random number to one column for 500 records?

I try to set up a testing sample table which contain one integer project_ID field for table Sample around 500 records, and want the project_ID to be random number within 1 to 99, how to implement script todo it?

thanks!

Here you go !
using System
namespace x {
classe y {
public y () {}
public int getRandomID () {
Random r = new Random()
return r.Next(1,99); // this indicates the start and end limit of the random function
}
}
}

then use the returned value into your SQL query to generate the records... make sure you dont have the project_ID as primary key as this above code does not check for uniqueness of the generated number....
HTH

Friday, March 23, 2012

How to alter column in Micorsoft SQL

Hi,
I have the following sample code to alter two table columns. But it
did not work. Please help me out. Thanks!
drop table one ;
create table one (
a float NOT NULL,
b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
alter table one
alter column a (NULL) ,
alter column b (NULL)
;
Thanks,
Mike
On Feb 1, 2:09 am, "Michael" <michae...@.gmail.com> wrote:
> Hi,
> I have the following sample code to alter two table columns. But it
> did not work. Please help me out. Thanks!
> drop table one ;
> create table one (
> a float NOT NULL,
> b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> )
> alter table one
> alter column a (NULL) ,
> alter column b (NULL)
> ;
> Thanks,
> Mike
Hi Mike,
Perhaps you are not using Books Online properly.
The following code does what u wann.
ALTER TABLE ONE
ALTER COLUMN A FLOAT NULL
ALTER TABLE ONE
ALTER COLUMN B VARCHAR NULL
Thanks
Dutt...

How to alter column in Micorsoft SQL

Hi,
I have the following sample code to alter two table columns. But it
did not work. Please help me out. Thanks!
drop table one ;
create table one (
a float NOT NULL,
b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
alter table one
alter column a (NULL) ,
alter column b (NULL)
;
Thanks,
MikeOn Feb 1, 2:09 am, "Michael" <michae...@.gmail.com> wrote:
> Hi,
> I have the following sample code to alter two table columns. But it
> did not work. Please help me out. Thanks!
> drop table one ;
> create table one (
> a float NOT NULL,
> b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> )
> alter table one
> alter column a (NULL) ,
> alter column b (NULL)
> ;
> Thanks,
> Mike
Hi Mike,
Perhaps you are not using Books Online properly.
The following code does what u wann.
ALTER TABLE ONE
ALTER COLUMN A FLOAT NULL
ALTER TABLE ONE
ALTER COLUMN B VARCHAR NULL
Thanks
Dutt...

How to alter column in Micorsoft SQL

Hi,
I have the following sample code to alter two table columns. But it
did not work. Please help me out. Thanks!
drop table one ;
create table one (
a float NOT NULL,
b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
)
alter table one
alter column a (NULL) ,
alter column b (NULL)
;
Thanks,
MikeOn Feb 1, 2:09 am, "Michael" <michae...@.gmail.com> wrote:
> Hi,
> I have the following sample code to alter two table columns. But it
> did not work. Please help me out. Thanks!
> drop table one ;
> create table one (
> a float NOT NULL,
> b varchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> )
> alter table one
> alter column a (NULL) ,
> alter column b (NULL)
> ;
> Thanks,
> Mike
Hi Mike,
Perhaps you are not using Books Online properly.
The following code does what u wann.
ALTER TABLE ONE
ALTER COLUMN A FLOAT NULL
ALTER TABLE ONE
ALTER COLUMN B VARCHAR NULL
Thanks
Dutt...