January 20, 2009 at 5:12 am
munishprathap (1/20/2009)
Ok thts greatits having 10 rows and one column have DateTime type with values.
Do these date-time values mean anything? what are your rules for converting a date to integer while still keeping the same value as you will not be able to put a datetime into an int column..
January 20, 2009 at 5:19 am
munishprathap (1/19/2009)
Thanks Jeffaccording to my requirement i need to keep the one column type as bigint but unfortunately
i keep it as DateTime after long time i found that it was DateTime Type. so i need to write
a Script / Query which updates the Column field type as BigInt from DateTime and set the ID Column as
Identity with primary key.
My Table Script
CREATE TABLE [dbo].Number (
[ID] [BIGINT] NOT NULL,
[LastModifyBy] [DATETIME] NOT NULL)
Please stop and think a minute and I'll give you the answer. What is the purpose of storing a DateTime as a BigInt? I need to know the real reason... not that it's simply a requirement you've been given.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2009 at 5:20 am
munishprathap (1/20/2009)
Ok thts greatits having 10 rows and one column have DateTime type with values.
Is this table heavily used at present?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 20, 2009 at 5:20 am
No
January 20, 2009 at 5:25 am
munishprathap (1/20/2009)
No
If no other students are using it, why don't you simply script a new table using EM and copy the data into it?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 20, 2009 at 5:29 am
in future table will have more than thoushand of records
at tht time thy dnt need to copy the table content
thy need only to change the data type Datetime to bigint thts it
January 20, 2009 at 5:45 am
munishprathap (1/20/2009)
in future table will have more than thoushand of recordsat tht time thy dnt need to copy the table content
thy need only to change the data type Datetime to bigint thts it
Excellent, then use EM to create a new table. Delete the existing one first. Much easier than using those pesky scripts, isn't it?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 20, 2009 at 6:00 am
munishprathap (1/20/2009)
thy need only to change the data type Datetime to bigint thts it
WHY??? This is one of the worst things you can do in a database! And just saying it's a requirement isn't the right thing to do either. What is the business need for this horrible change?
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2009 at 6:12 am
I'm with Jeff on this, why do you need to make the change?
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
January 20, 2009 at 6:19 am
Christopher Stobbs (1/20/2009)
I'm with Jeff on this, why do you need to make the change?
Because...
There's no data in the table, although for the purpose of this exercise we must assume that there are about 10. None of the other students are using the table, of course :Whistling:
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 20, 2009 at 6:24 am
Chris Morris (1/20/2009)
Christopher Stobbs (1/20/2009)
I'm with Jeff on this, why do you need to make the change?Because...
There's no data in the table, although for the purpose of this exercise we must assume that there are about 10. None of the other students are using the table, of course :Whistling:
Doesn't matter if there's 0 data or a billion rows... it's a terrible change to make and if an instructor is teaching someone that this is the right thing to do, (s)he needs to be drawn and quartered. I'm trying to get people to start asking questions instead of just becoming another SQL Clone that blindly does bad things to the database because someone made a bad decision. "Because" is never the correct answer on such things.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2009 at 7:07 am
Jeff Moden (1/20/2009)
Doesn't matter if there's 0 data or a billion rows... it's a terrible change to make and if an instructor is teaching someone that this is the right thing to do, (s)he needs to be drawn and quartered. I'm trying to get people to start asking questions instead of just becoming another SQL Clone that blindly does bad things to the database because someone made a bad decision. "Because" is never the correct answer on such things.
Jeff, you've got a result when the OP submits an answer which consists of a workable script for performing this task - whether we like it or not, there may be marks riding on it - but with the comments "Why you should not do this" and "Here's the best way to do it" - and an understanding of both. For now, he's still trying to figure out how to persuade someone to write his script without letting on that it's coursework. There's a long way to go.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 20, 2009 at 9:28 pm
Chris Morris (1/20/2009)
For now, he's still trying to figure out how to persuade someone to write his script without letting on that it's coursework.
Heh.... then there's that. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
January 20, 2009 at 10:57 pm
Thanks friends for all your support
i can achieve this task by the following Query,please let me know your feedback
IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Note'
AND COLUMN_NAME = 'LastModifyBy'
AND DATA_TYPE = 'datetime' )
BEGIN
ALTER TABLE [dbo].[Note] ALTER COLUMN LastModifyBy VARCHAR
UPDATE [dbo].[Note]
SET LastModifyBy='0'
ALTER TABLE [dbo].[Note] ALTER COLUMN LastModifyBy BIGINT
END
January 21, 2009 at 6:32 am
munishprathap (1/20/2009)
Thanks friends for all your supporti can achieve this task by the following Query,please let me know your feedback
IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'Note'
AND COLUMN_NAME = 'LastModifyBy'
AND DATA_TYPE = 'datetime' )
BEGIN
ALTER TABLE [dbo].[Note] ALTER COLUMN LastModifyBy VARCHAR
UPDATE [dbo].[Note]
SET LastModifyBy='0'
ALTER TABLE [dbo].[Note] ALTER COLUMN LastModifyBy BIGINT
END
That probably won't do it if the table contains data.
Lemme ask again... what is the business reason for doing this? All ya gotta do is share that teeny bit of info and you can get the help you need. And, just saying it's a requirement won't cut it... I need to know why someone wants to do this. The reason why I want that information up front is because very few people take the time to explain once they've been given the answer.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 16 through 30 (of 32 total)
You must be logged in to reply to this topic. Login to reply