sql:PostgreSQL
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的更多相关文章
- sql: postgreSQL sql script
SELECT * from pg_class c,pg_attribute a,pg_type t where c.relname='BookKindList' and a.attnum>0 a ...
- PostgreSQL的.NET驱动程序Npgsql
Npgsql是PostgreSQL的一个.NET数据提供程序,它可以自由获取.它可以通过下列选项获得独立的下载,也可以安装PostgreSQL数据库程序时选择安装. 最新的_npgsql2 Npgsq ...
- Fluent NHibernate and Mysql,SQLite,PostgreSQL
http://codeofrob.com/entries/sqlite-csharp-and-nhibernate.html https://code.google.com/archive/p/csh ...
- 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 ...
- PostgreSQL指南
PostgreSQL指南 历史简介 最近几年Postgres的关注度变得越来越高. 它加快了Postgres的发展步伐, 与此同时其他 的关系数据库系统的发展放缓. 在数据库领域中 Postgre S ...
- mysql+postgresql备份与恢复
mysql备份一个库, mysqldump -u用户名 -p密码 [选项] [数据库名] > /备份路径/备份文件名 mysqldump -uuser -p123123 auth > / ...
- How to make PostgreSQL functions atomic?
Question: How to make PostgreSQL functions atomic? Assume I have some PostgreSQL functions like the ...
- PostgreSQL 备份和恢复
备份和恢复有三种不同的基本方法来备份PostgreSQL数据SQL转储文件系统级备份File system level backup连续归档 1. SQL转储 pg_dump dbname > ...
- PostgreSQL 二进制安装
一.安装前准备工作 新建用户 sudo groupadd sql sudo useradd -g sql postgressudo passwd postgres 创建数据及日志目录,并做相应授权 s ...
随机推荐
- mxonline实战6 , 忘记用户密码时进行重置
对应github地址:密码重置 原理: 1. 一个需要输入用户邮箱和注册码的密码忘记页面 2. 点击提交后,用户邮箱收到一个邮件,包含重置密码的链接 3. 点击链接进入密码重置页面 ...
- springMVC传递一组对象的接受方式
受益此大神:https://blog.csdn.net/cgd_8523/article/details/80022331 同时借鉴代码!!!! 我只用了一种方法,就记下这一种 需求:前台存在动态添加 ...
- django 的 安全机制
xss 保护: xss攻击允许用户注入客户端脚本到其他用户的服务器上.通常通过存储恶意脚本到数据库,其他用户通过数据库获取恶意脚本,并在浏览器上呈现:或是使用户点击会引起攻击者javascirpt脚本 ...
- leetcode-849-到最近的人的最大距离
题目描述: 在一排座位( seats)中,1 代表有人坐在座位上,0 代表座位上是空的. 至少有一个空座位,且至少有一人坐在座位上. 亚历克斯希望坐在一个能够使他与离他最近的人之间的距离达到最大化的座 ...
- 数据结构基础 ---- 数组的理解和实现(Java)
什么是数组 数组是由类型相同的数据元素构成的有序集合,每个元素称为数组元素,每个元素受n(n>= 1)个线性关系的约束,每个元素在n个线性关系中的序号i1, i2, ....., in称该元素的 ...
- JS使用Crypto实现AES/ECS/zero-padding加密
首先说一句,no-padding和zero-padding是一样的.他们指的是不够16位的情况补0至16位. 天知道网上为什么会出现两种叫法. 另附两个有用的网址 http://tool.chacuo ...
- LINQ入门教程之各种标准查询操作符(一)
好久之前就想系统的学习下LINQ,好久之前…… 本篇文章主要介绍LINQ等的标准查询操作符,内容取自<LINQ高级编程>,后续还会介绍LINQ to XML ,LINQ to SQL. L ...
- normalize.css源码解析
什么是normalize.css? 它是为了帮助我们统一各个浏览器的样式和消除bug的css库. 为什么需要normalize.css,有什么好处? 不像一些reset.css,normalize. ...
- C# 委托进阶
本文参考自:https://wenku.baidu.com/view/41ab91d3c1c708a1284a44d7.html?qq-pf-to=pcqq.c2c 1.为什么委托定义的返回值通常为v ...
- 第3章—高级装配—条件化的Bean
条件化的Bean 通过活动的profile,我们可以获得不同的Bean.Spring 4提供了一个更通用的基于条件的Bean的创建方式,即使用@Conditional注解. @Conditional根 ...