Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need Help with the ALTER command

Author  Topic 

lallous
Starting Member

12 Posts

Posted - 2005-12-16 : 17:41:26
Hello everyone,
I just started learning sql and I came across a slight problem.
Assume I have a customer table composed of the following fields:
Customer_Number,Sname,Street,City,Postcode,credit_lim,balance.

What I want to do is to drop the Street,city,and postcode fields and add the following: fax,email,and phone.

Is it possible to use the following command:

Alter table customer
Drop column street,city,postcode


Or should I do as following:

Alter table customer
Drop column street

Alter table customer
Drop column city

Alter table customer
Drop column postcode

And the same goes to adding the phone,fax,and email field.
Thank You.

NB: I need to use the Alter command and nothing else

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-16 : 17:49:13
According to SQL Server Books Online ALTER TABLE article, you should be able to do it like this. I don't think you'd be able to combine the DROP COLUMN and ADD into one statement though.

ALTER TABLE Customer
DROP COLUMN Street, City, Postcode
GO

ALTER TABLE Customer
ADD Fax varchar(10) NULL, Email nvarchar(256) NULL, Phone varchar(10) NULL
GO

For any other homework questions, please consult SQL Server Books Online so that you can learn how to write T-SQL rather than us giving you the answer.

Tara Kizer
aka tduggan
Go to Top of Page

lallous
Starting Member

12 Posts

Posted - 2005-12-17 : 05:03:47
Hello and thank you for the reply,

I just need to learn how to write proper syntax because the book(http://www.databasedesign.co.uk/bookdbdpvbawebpages/root.htm from John Carter the one in orange) i am using to study SQL doesnt state how to Alter several columns at a time (thats why i asked).

And i was trying to figure out how to test my sql statements, is there any software which can check a given statement?

I got MS Access installed but i am not sure if i can write sql statements in any other place than querries.Can someone tell me if it is possible to write SQL statements in Access?

Thank You and forgive me for my annoying questions.
Go to Top of Page

lallous
Starting Member

12 Posts

Posted - 2005-12-18 : 02:50:47
No help :(
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-19 : 00:03:14
>> i am not sure if i can write sql statements in any other place than querries.

I think you need to write sql scripts at Queries
Why do you want to write other than Queries?



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-19 : 01:15:27
Query Analyzer can check your queries and you can run them in it if you also installed the database engine. You can get the developer edition of SQL Server for only 49 bucks. It's a full licensed version, you just can't use it in production.

BTW, you won't typically find too many people answering questions on the weekend so that's why your question went unanswered for a day.

Tara Kizer
aka tduggan
Go to Top of Page

lallous
Starting Member

12 Posts

Posted - 2005-12-19 : 13:11:11
quote:
Originally posted by madhivanan

>> i am not sure if i can write sql statements in any other place than querries.

I think you need to write sql scripts at Queries
Why do you want to write other than Queries?



I was just wondering because i want to try to create tables(using SQL) thats why i thought if there might be some other place to do that.
quote:
BTW, you won't typically find too many people answering questions on the weekend so that's why your question went unanswered for a day.


Thanks for informing me because I was wondering where everyone disappeared all of a sudden

And BTW the Commands worked great,
Thank You
Go to Top of Page

lallous
Starting Member

12 Posts

Posted - 2005-12-19 : 13:53:43
I am getting a:

'Table "Payment"Already exists' problem when trying to create a table. I am sure that i havent created it from before. I have the Customer and Invoice table created now i am creating the Payment table. Is there any specific problem going on here?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-19 : 13:57:50
It already exists. So you must drop it first before trying to create it. Is this for Access or SQL Server? If Access, then your questions should be posted in the Access forum.

Tara Kizer
aka tduggan
Go to Top of Page

lallous
Starting Member

12 Posts

Posted - 2005-12-19 : 14:01:28
I am sorry but this access i am working on now. I will try using the drop command.

This is so weird , still not working , This is my DB: http://rapidshare.de/files/9465744/db1.zip.html
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-19 : 14:12:10
You've reached an MS SQL Server forum. Answers given will be for SQL Server and not for Access. I'd suggest posting in the Access forum so that you get Access answers.

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -