PostgreSQL sql script:

-- Database: geovindu

-- DROP DATABASE geovindu;

CREATE DATABASE geovindu
WITH OWNER = postgres
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'Chinese_People''s Republic of China.936'
LC_CTYPE = 'Chinese_People''s Republic of China.936'
CONNECTION LIMIT = -1; --创建表
create table BookKindList
(
BookKindID SERIAL PRIMARY KEY,
BookKindName varchar(500) not null,
BookKindCode varchar(100) null,
BookKindParent int null
); --查询
select * from BookKindList;
--添加
insert into BookKindList(BookKindName,BookKindParent) values('六福书目录',0); insert into BookKindList(BookKindName,BookKindParent) values('文学',1);
insert into BookKindList(BookKindName,BookKindParent) values('设计艺术',1);
insert into BookKindList(BookKindName,BookKindParent) values('自然科学',1); insert into BookKindList(BookKindName,BookKindParent) values('小说',2);
insert into BookKindList(BookKindName,BookKindParent) values('诗词散曲',2); select * from BookKindList where BookKindID=1;
--返回增加的ID
select lastval();

  csharp:

 /// <summary>
/// 涂聚文 20150212
/// PostgreSql添加返回值ID
/// </summary>
/// <param name="SQLString"></param>
/// <param name="identity"></param>
/// <param name="cmdParms"></param>
/// <returns></returns>
public static int ExecuteSql(string SQLString, out int identity, params NpgsqlParameter[] cmdParms)
{
string en = "";
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
using (NpgsqlCommand cmd = new NpgsqlCommand())
{
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int rows = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
cmd.CommandText = "select lastval();";
en = cmd.ExecuteScalar().ToString();
identity = int.Parse(en);
cmd.Parameters.Clear();
return rows;
}
catch (NpgsqlException E)
{
throw new Exception(E.Message);
}
}
}
} /// <summary>
/// 追回返回值
/// PostgreSql涂聚文
/// </summary>
/// <param name="bookKindList"></param>
/// <param name="id"></param>
/// <returns></returns>
public int InsertBookKindOut(BookKindListInfo bookKindList, out int id)
{
int ret = 0;
int tid = 0;
try
{
StringBuilder str = new StringBuilder();
str.Append("insert into BookKindList(BookKindName,BookKindCode,BookKindParent) values(");
str.Append("@BookKindName,@BookKindCode,@BookKindParent);");
NpgsqlParameter[] par = new NpgsqlParameter[]{
new NpgsqlParameter("@BookKindName",DbType.String,1000),
new NpgsqlParameter("@BookKindCode",DbType.String,1000),
new NpgsqlParameter("@BookKindParent",DbType.Int32,4),
//new NpgsqlParameter("@BookKindID",DbType.Int32,4),
};
par[0].Value = bookKindList.BookKindName;
par[1].Value = bookKindList.BookKindCode;
par[2].Value = bookKindList.BookKindParent;
//par[3].Direction = ParameterDirection.Output;//无效 不支持
ret = PostgreSqlHelper.ExecuteSql(str.ToString(), out tid, par);
if (ret > 0)
{
//tid = ret;// (int)par[3].Value;
}
}
catch (NpgsqlException ex)
{
throw ex;
}
id = tid; return ret;
}

  

sql:PostgreSQL的更多相关文章

  1. sql: postgreSQL sql script

    SELECT * from pg_class c,pg_attribute a,pg_type t where c.relname='BookKindList' and a.attnum>0 a ...

  2. PostgreSQL的.NET驱动程序Npgsql

    Npgsql是PostgreSQL的一个.NET数据提供程序,它可以自由获取.它可以通过下列选项获得独立的下载,也可以安装PostgreSQL数据库程序时选择安装. 最新的_npgsql2 Npgsq ...

  3. Fluent NHibernate and Mysql,SQLite,PostgreSQL

    http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...

  4. PostgreSQL pg_dump pg_dumpall and restore

    pg_dump dumps a database as a text file or to other formats. Usage: pg_dump [OPTION]... [DBNAME] Gen ...

  5. PostgreSQL指南

    PostgreSQL指南 历史简介 最近几年Postgres的关注度变得越来越高. 它加快了Postgres的发展步伐, 与此同时其他 的关系数据库系统的发展放缓. 在数据库领域中 Postgre S ...

  6. mysql+postgresql备份与恢复

    mysql备份一个库, mysqldump  -u用户名 -p密码 [选项] [数据库名] > /备份路径/备份文件名 mysqldump -uuser -p123123 auth > / ...

  7. How to make PostgreSQL functions atomic?

    Question: How to make PostgreSQL functions atomic? Assume I have some PostgreSQL functions like the ...

  8. PostgreSQL 备份和恢复

    备份和恢复有三种不同的基本方法来备份PostgreSQL数据SQL转储文件系统级备份File system level backup连续归档 1. SQL转储 pg_dump dbname > ...

  9. PostgreSQL 二进制安装

    一.安装前准备工作 新建用户 sudo groupadd sql sudo useradd -g sql postgressudo passwd postgres 创建数据及日志目录,并做相应授权 s ...

随机推荐

  1. 敏感词过滤的算法原理之 Aho-Corasick 算法

    参考文档 http://www.hankcs.com/program/algorithm/implementation-and-analysis-of-aho-corasick-algorithm-i ...

  2. 在linux云服务器上运行Jar文件

    在linux服务器上运行Jar文件时通常的方法是: $ java -jar test.jar 这种方式特点是ssh窗口关闭时,程序中止运行.或者是运行时没法切出去执行其他任务,有没有办法让Jar在后台 ...

  3. random 模块常用方法学习

    >>> import random#随机小数>>> random.random() # 大于0且小于1之间的小数0.7664338663654585>> ...

  4. [Alpha]Scrum Meeting#9

    github 本次会议项目由PM召开,时间为4月11日晚上10点30分 时长10分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写每日例会报告 撰写每日例会报告撰写并整理任务分配博客 SiMrua ...

  5. (转)zabbix3.4使用percona-monitoring-plugins监控mysql

    原文:https://blog.csdn.net/yanggd1987/article/details/79656771 简介 之前主要使用nagios监控mysql,本文主要介绍使用percona- ...

  6. web前端优化之reflow(减少页面的回流)

    1.什么是reflow? reflow(回流)是指浏览器为了重新渲染部分或者全部的文档,重新计算文档中的元素的位置和几何构造的过程. 因为回流可能导致整个Dom树的重新构造,所以是性能的一大杀手. 以 ...

  7. thinkPHP5配置nginx环境无法打开(require(): open_basedir restriction in effect. File(/mnt/hgfs/root/tp5/thinkphp/start.php) is not within the allowed path(s)

    今天想把玩一下tp5,结果怎么都无法访问,每次都是报500错误,我把错误提示都打开看到下面的错误 require(): open_basedir restriction in effect. File ...

  8. Java Servlet 缺点

    1.web.xml配置比较多 2.servlet具有容器依赖性(tomcat没有启动,就没有用)

  9. 使用 JFlex

    参数设置和声明段 %% 词法规则段 用户代码段这个段中的所有内容将被拷贝到生成的词法类的类声明之前.在这个段中,常见的是 package 和 import 语句.我们的词法说明在这个段中引入(impo ...

  10. java的instanceof简单使用

    instanceof:是java中用来判断一个对象属于哪个类型的关键字 (instanceof是instance和of两个单词组成,但of并没有大写) eg: public class Test{   ...