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
 [PostgreSQL] solution for alter and drop

Author  Topic 

alper
Starting Member

5 Posts

Posted - 2011-02-02 : 04:24:07
Guys I need a little bit support on this:

My question is related to the following table:


In the table, I have to create an item that is a meaningless primary key called ''banr''. I need a SQL script that makes this change. I have to use Alter and Drop statements, but I really do not know how I can use ALTER and DROP?
The uniqueness rule for the columns Order, article should be retained.

I think that I have to follow these steps but i am not sure and don't know what is the best way and how it will look like.
1. Create a new table with primary key or ID with name ''banr'' with AUTOINCREMENT and which is meaningles, + other fields.
2. insert into new_table and select from old table
3. Drop old table
4. rename new table to old table

How can I make this script? How does it looks like? If anyone can help a little way. Many thanks!

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2011-02-03 : 06:28:59
What do you have so far?

-----------

I used to think I wasn't a morning person but it never got better in the afternoon
Go to Top of Page

alper
Starting Member

5 Posts

Posted - 2011-02-03 : 06:46:58
Elwoos, I didn't find how to fix this (using ALTER AND DROP). I don't know anything about ALTER.

So far:



CREATE TABLE BESTELDARTIKEL (
banr number(11) NOT NULL,
bestelnr number(11) NOT NULL,
artikelcode number(11) NOT NULL,
aantal number(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY ( bestelnr) REFERENCES bestelling ( bestelnr),
( artikelcode) REFERENCES artikel ( artikelcode);

Now is my question, where and how can I add ALTER and DROP?



Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2011-02-03 : 09:25:09
http://www.google.com/search?q=postgresql+alter+table
http://www.google.com/search?q=postgresql+drop+table



elsasoft.org
Go to Top of Page

alper
Starting Member

5 Posts

Posted - 2011-02-03 : 09:46:00
quote:
Originally posted by jezemine

http://www.google.com/search?q=postgresql+alter+table
http://www.google.com/search?q=postgresql+drop+table



elsasoft.org

I've tried google before, but I just don't understand POSTGRESQL. Crappy program.
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2011-02-04 : 05:23:05
Jezemine's links are the Postgres equivalent of BOL, though you should make sure you are looking at those relevant to the version of postgres you are accessing.

The statement you have given creates the table, The syntax for the alter statement described in Jezemine's first link.

In practice the syntax is largely similar to that for SQL Server (though there are some differences such as the semi-colon at the end of a command)

For the drop table - the most basic command would be the same as sql server e.g. DROP TABLE MyTable; The only difference here to that used for SQL Server is the semicolon at the end.

From the steps you gave, you have done step 1, that's in your statement above. Step 2 is an INSERT and SELECT like any other on this site or elsewhere. Step 3 we have discussed above, step 4 is described in the documentation that Jezemine linked to - if you read it you will see the Rename option.

If you want to learn more about PostGres there are plenty of sites to find it, this one is specifically for MS SQL Server, it just happens that I know a little about PostGres.

-----------

I used to think I wasn't a morning person but it never got better in the afternoon
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2011-02-04 : 08:10:49
also don't understand shouldn't equal crap.

I don't understand general relativity. does that mean it's crap?


elsasoft.org
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-02-04 : 08:23:01
quote:
Originally posted by jezemine

also don't understand shouldn't equal crap.

I don't understand general relativity. does that mean it's crap?


elsasoft.org



Quote of the month! Thanks for that jezemine lol
Go to Top of Page

alper
Starting Member

5 Posts

Posted - 2011-02-04 : 08:56:14
quote:
Originally posted by jezemine

also don't understand shouldn't equal crap.

I don't understand general relativity. does that mean it's crap?


elsasoft.org

Very funny. Thanks for your help...NOT

MODS, please close topic.
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2011-02-04 : 09:25:01
well the links I gave you would help you learn how to drop and alter tables if you read them. there are examples of how to drop and alter tables right there in the pgsql documentation. I figured there's no point in regurgitating the example here since they are already on the web elsewhere.

sorry the links didn't help you.


elsasoft.org
Go to Top of Page

alper
Starting Member

5 Posts

Posted - 2011-02-04 : 09:57:25
quote:
Originally posted by jezemine

well the links I gave you would help you learn how to drop and alter tables if you read them. there are examples of how to drop and alter tables right there in the pgsql documentation. I figured there's no point in regurgitating the example here since they are already on the web elsewhere.

sorry the links didn't help you.


elsasoft.org

Oke jezemine, thank you.
Go to Top of Page

wajeeha20
Starting Member

13 Posts

Posted - 2011-09-26 : 04:53:43
hey alper

didt you understood anything of POstgreSQL? coz i have the same problem.
I have to run a postgresql database. and I do not know what is the difference between a postgresql database and ms sql database? What should I do? can anyone help me? I need new tools to run postgresql database?

please help me: (
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2011-09-26 : 12:06:18
There are plenty of tools for postgres sql - http://wiki.postgresql.org/wiki/Community_Guide_to_PostgreSQL_GUI_Tools as for the difference between the two, google is your friend http://www.google.co.uk/search?q=difference+between+postgres+and+ms+sql+server

-----------

What color do you want that database?
Go to Top of Page
   

- Advertisement -