Chinaunix首页 | 论坛 | 博客
  • 博客访问: 697655
  • 博文数量: 160
  • 博客积分: 8847
  • 博客等级: 中将
  • 技术积分: 1656
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 16:46
个人简介

。。。。。。。。。。。。。。。。。。。。。。

文章分类

全部博文(160)

文章存档

2015年(1)

2013年(1)

2012年(4)

2011年(26)

2010年(14)

2009年(36)

2008年(38)

2007年(39)

2006年(1)

分类: Mysql/postgreSQL

2011-03-16 15:47:42


配置YII
打开主配置文件main.php
        'db'=>array(
            'connectionString' => 'pgsql:host=localhost;port=5432;dbname=trackstar_dev',
            'emulatePrepare' => true,
            'username' => 'dev',
            'password' => '数据库拥有者密码',
            'charset' => 'utf8',
        ),

新建一个用户development,并设置为administrators组。因为建立表空间的时候,pgsql会检查用户是否有写的权限,否则会提示无权限写入。

一、新建角色组:

CREATE ROLE development;

二、新建角色:

CREATE ROLE dev LOGIN;

GRANT development to dev;

三、新建表分区:

CREATE TABLESPACE dev

  OWNER development 

  LOCATION 'd:/xampp/postgredb/dev';

四、建立数据库

CREATE DATABASE trackstar_dev

  WITH OWNER = dev

TABLESPACE dev

 ENCODING = 'UTF8';

五、建表

trackstar_dev=# \c trackstar_dev

CREATE TABLE tbl_user

(

  id serial NOT NULL,

  username character(32NOT NULL,

  "password" character(32NOT NULL,

  email character(32NOT NULL,

  last_login_time time without time zone,

  create_user_id integer,

  create_time time without time zone,

  update_user_id integer,

  update_time time without time zone,

  CONSTRAINT tbl_user_pkey PRIMARY KEY (id)

)

WITH (OIDS=FALSE);

ALTER TABLE tbl_user OWNER TO development;

NOTICE:  CREATE TABLE will create implicit sequence "tbl_user_id_seq" for serial column "tbl_user.id"

NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "tbl_user_pkey" for table "tbl_user"

查询成功但无结果,耗时: 94 毫秒(ms)

pgsql为我们建立了序列,也就相当于mysql里面的auto_increament字段。

这个序列也可以自定义:

CREATE SEQUENCE common_fruit_id_seq;

CREATE TABLE apples (

    id      INT4 DEFAULT nextval('common_fruit_id_seq'NOT NULL,

    price   NUMERIC

);

CREATE TABLE oranges (

    id      INT4 DEFAULT nextval('common_fruit_id_seq'NOT NULL,

    weight  NUMERIC

);

六、查看表结构

\d+ tbl_user

七、修改表结构

  1. alter table tbl_user drop column last_login_time;

  2. alter table tbl_user add column last_login_time timestamp without time zone;

  3. alter table tbl_user drop column create_time;

  4. alter table tbl_user add column create_time timestamp without time zone;

  5. alter table tbl_user drop column update_time;

  6. alter table tbl_user add column update_time timestamp without time zone;

  7. insert into tbl_user(username, password, email, last_login_time) values('liujun',md5('liujun'), 'liu1084@163.com', '2010-03-16 15:24:54');

  8. select * from tbl_user;


八、清空表‘

truncate tbl_user;

九、插入数据

insert into tbl_user(username, password, email, last_login_time) values('liujun',md5('liujun'), 'liu1084@163.com', '2010-03-16 15:24:54');

十、查看数据

select * from tbl_user;


阅读(814) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~