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 ...
随机推荐
- SpringBoot整合MyBatis及Thymeleaf
http://www.cnblogs.com/ludashi/archive/2017/05/08/6669133.html 上篇博客我们聊了<JavaEE开发之SpringBoot工程的创建. ...
- keycloak ssl-required报错问题处理
两台主机,网段不同,第一台129.30.108.179/24 第二台172.16.160.92/24 都安装keycloak : docker run -d --name keycl ...
- laravel 表单接收
POST方式接收 视图层 <form action="/submit" method="post"> {{csrf_field()}} //必 ...
- postgresql客户端连接错误的解决方法【转】
今天在重新设置postgresql服务器以后却发现启动不了服务器.错误如下:psql: could not connect to server: No such file or directory ...
- FindLine把多行查找改为多行替换
Sub FindLine() Dim textSelection As TextSelection textSelection = DTE.ActiveDocument.Selection textS ...
- 非常不错的app和网站
置顶: word.pdf之间相互转换的网站: https://www.addpdf.cn 很棒啊 1. Global Potplayer 这个软件简直了,播放各种视频, 无论是本地的,还是在线的,都非 ...
- Linux系统编程:线程控制
一.提出问题 问1.线程存在的意义是什么?什么时候适合使用多线程? 答1.在单进程环境中实现多任务,线程可访问其所在进程的资源,例如内存.描述符等.对于单进程,如果要完成多项任务,这些任务只能依次执行 ...
- JS中typeof和instanceof的用法和区别
typeof和instanceof的区别 instanceof 常用来判断一个变量是否为空,或者是什么类型的.但它们之间还是有区别的 instanceof的用法 instanceof返回的是一个布尔值 ...
- git --mixed --soft --hard之间的区别
git reset --mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和add信息git reset --soft:回退到某个 ...
- python-Unix套接字
#!/usr/bin/python #coding=utf-8 #server import socket import sys import os server_address = './test' ...