To start on creating the database, on postgres, as I said before, is very unlike mysql. In mysql, it is calling createdb on mysql shell. On postgres, you call on shell:
createdb databasenameif something happen and you want to drop it, it is done by calling
dropdb databasenamethen you call
psql databasenamehere i assume, that you create a user, in postgresql server that is your name. Suppose the above command doesn't doesn't work, do this, which I only tested on ubuntu, on other you might need to login as postgres user:
sudo -u postgres psqlnow you can create tables, which again, very different from mysql. With many similarity as well.
in the psql shell, create table like this:
create table contact(Which very similar with mysql, except, why id is serial?
id serial primary key,
name varchar(255),
address text,
email varchar(255)
);
Well, it turn out that, there is no autoincrement on postgresql, but it have a serial, which is really an autoincrementing integer. So that's interesting.
Actually this is just the very surface of postgresql sql. Actually, there is many features, that mysql don't have or have it very recently. such as
- inheritance, you can, inherit from another table, ala oop. mysql don't have that
- procedural language, which mysql, introduced stored procedure in mysql 5. not too long ago.
I barely touch this, so there is more adventure for me in the future
No comments:
Post a Comment