Recently, SQL stored procedures have been found to greatly reduce the amount of code in the program.
In the future, we need to consider using more stored procedures.
Two tips:
1. Use stored procedures to dynamically create data tables.
/*
Process function: dynamically create a data table in a stored procedure
Note: connect the "single quotation marks" of the SQL statement"
Created on: 2006-09-01
Created by: skyjacker
Blog: http: // blog.csdn.net/skyjacker
*/
Create procedure [DBO]. [createtable]
@ Tablename varchar (255)
As
Begin
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. ['+ @ tablename +'] ') and
Objectproperty (ID, N 'isusertable') = 1)
Exec ('drop table' + @ tablename );
Exec ('
Create Table [DBO]. ['+ @ tablename +'] (
[ID] [varchar] (50) Collate chinese_prc_ci_as null,
[Name] [varchar] (50) Collate chinese_prc_ci_as null
) On [primary] ')
End;
Go
Execute exec createtable 'tabhello'
2. Insert a new record.
/*
Process functions:
Insert new record
If yes, no insert
Insert if it does not exist
Note: There should be better methods
Created on: 2006-09-01
Created by: skyjacker
Blog: http: // blog.csdn.net/skyjacker
*/
Create procedure lyrtypetable
@ Maplayer varchar (255 ),
@ Type varchar (255 ),
@ Drawtool varchar (255)
As
Begin
Declare @ recordnum integer
Set @ recordnum = 0
Select top 1 maplayer from tabtest where maplayer = @ maplayer
Set @ recordnum = @ rowcount
If (@ recordnum = 0)
Insert into tabtest (maplayer, type, drawtool) values (@ maplayer, @ type, @ drawtool)
End;
Go