StoredProcedureInsert <%-- Name:SQL StoredProcedureInsert Author: XuYabao Description: StoredProcedureInsert --%> <%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" ResponseEncoding="UTF-8" Description="Generates a insert stored procedure." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the stored procedures should be based on." %> <%@ Property Name="Author" Type="String" Default="徐亚豹" Category="Context" Description="Author." %> <%@ Property Name="IdentityColumn" Type="Int32" Default="0" Category="Context" Description="Is Return Identity. =0:No,>0:Yes" %> <%@ Property Name="Description" Type="String" Default="新增" Category="Context" Description="Description." %> <mce:script runat="template"><!-- public string GetSqlParameterStatement(ColumnSchema column) { string param = "@" + column.Name + " " + column.NativeType; switch (column.DataType) { case DbType.Int32: break; case DbType.Int64: break; case DbType.Double: break; case DbType.DateTime: break; case DbType.Decimal: { param += "(" + column.Precision + ", " + column.Scale + ")"; break; } default: { if (column.Size > 0) { param += "(" + column.Size + ")"; } break; } } return param; } // --></mce:script> ----------------------------------------------------------------- -- 描述: <% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %><%= Description %> -- 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> ----------------------------------------------------------------- CREATE PROCEDURE p_<%= SourceTable.Name.Substring(2) %>Add <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> <%= GetSqlParameterStatement(SourceTable.Columns[i]) %><% if (IdentityColumn == i + 1) { %> output<% } %><% if (i < SourceTable.Columns.Count - 1) { %>,<% }%> --<%= SourceTable.Columns[i].Description%> <% } %> AS INSERT INTO <%= SourceTable.Name %> ( <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> <% if (IdentityColumn != i + 1) { %> <%= SourceTable.Columns[i].Name %><% if (i < SourceTable.Columns.Count - 1) { %>,<% } %> <% }} %> ) VALUES ( <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> <% if (IdentityColumn != i + 1) { %> @<%= SourceTable.Columns[i].Name %><% if (i < SourceTable.Columns.Count - 1) { %>,<% } %> <% }} %> ) <% if (IdentityColumn > 0) { %> SET @<%= SourceTable.Columns[IdentityColumn-1].Name %> = @@Identity <% } %>