Place Nouns in front and verbs in back.I personally recommend using method 2. The reason is as follows:
Take the NorthWind as an example. Assume that you have four stored procedures for the Employees table: prEmployeeInsert, prEmployeeUpdate, prEmployeeDelById, and prEmployeeGetById.
For the Products table, you have four similar stored procedures named prProductInsert, prProductUpdate, prProductDelById, and prProductGetById.
When you use the Enterprise Manager to view the data, you will find that the stored procedure is neatly arranged as follows:
PrEmployeeDelById
PrEmployeeGetById
PrEmployeeInsert
PrEmployeeUpdate
PrProductDelById
PrProductGetById
PrProductInsert
PrProductUpdate
It is easy to find that the more stored procedures you use, the more obvious the advantages of this naming method.
Name of parameters in Stored ProceduresThe entry parameters in the stored procedure are recommended to be the same as the corresponding field names. Here, we assume that you want to write a stored procedure (simplified) for updating the Employees table of the Northwind database. You can write this as follows:
Create Procedure prEmployeeUpdateById
@ EmployeeId Int,
@ LastName NVarchar (20 ),
@ FirstName NVarchar (10)
As
Update Employees Set
LastName = @ LastName,
FirstName = @ FirstName
Where
EmployeeId = @ EmployeeId
If @ error <> 0 or @ RowCount = 0
Raiserror 16001 'user update failed'
Reference
2 database naming principles
2.1 data files
If the database uses a file system instead of a bare device, the following naming rules are agreed:
1) Data Files start with the table space name and end with. dbf. All data files are named with lowercase English letters and numbers. If the tablespace contains multiple data files, add _ after the tablespace name starting from 2nd data files _.
For example, the system tablespace data files: system. dbf, system_2.dbf
2) control files of oracle databases are represented by control. ctl. For example, control01.ctl and control02.ctl.
3) for oracle Database Log Files, use redo for online log files <组名> <文件序列名> . Dbf. The group name and file sequence name are both represented by two digits. For example, the two files in the first group represent redo0101.dbf and redo0102.dbf. Archive logs are represented by arch _ % t _ % s. arc. Both % t and % s are oracle-Defined variables.
2.2 tablespace
2.2.1 Database System tablespace
The database system tablespace includes the system tablespace, temporary tablespace, and rollback segment tablespace. Specify the following naming rules:
1) The system tablespace is directly limited by the database and cannot be modified.
2) Temporary tablespace is represented by temp. If there are multiple temporary tablespaces, which start with 2nd temporary tablespaces, are added after temp.
3) The tablespace In the rollback segment is represented by undotbs. If there are more than one tablespace In the rollback segment, the table space starts from the first tablespace In the rollback segment and is added after undotbs.
2.2.2 Database User tablespace
The user tablespace of the database uses ts _ <表空间名> . Table space names are divided:
1) Data Space: The default tablespace is represented by default. For other tablespaces, they are represented based on the types of tables stored in the tablespaces. For example, the code table is represented by code. The table for storing customer data is represented by customer. Try to use a tablespace to store tables of this type. If a table is very large, you can use a single tablespace.
2) index space: Add ind _ before the name of the corresponding data table space _. For example, the index space of the user's default tablespace is represented by ts_ind_default. The index tablespace of the code table is represented by ts_ind_code.
Table 2.3
The naming rules for database tables are as follows:
1) The table name starts with T _. The table name cannot exceed 30 characters. The table name contains all words in the singular format, and the words must be capitalized.
2) Multiple words are connected by underscores. If there are multiple systems in the database, the table name is system name + word or multiple words. The system name is short for the development system, such as VNET.
3) We recommend that you use the complete words in the table. If the table name contains more than 30 characters, the abbreviation of the word is used forward from the last word. (If there is no contract abbreviation, it is represented by the first four letters of the word ).
The following rules are used to name fields in a database table:
1) All database Field Names use lower-case English words, separated. The field length cannot exceed 30 characters.
2) If the field is code, add _ id after the word.
3) If this field represents time, _ time is used as the suffix.
2.4 View
Database view naming rules are as follows:
1) The view name starts with V _. The view name cannot exceed 30 characters. View names are expressed in uppercase.
2) When a view is generated from several tables, it uses an underscore (_) to connect the names of several tables. If there are too many tables, you can simplify the table name, but make sure to list all the table names.
Sequence 2.5
Database sequence naming rules are as follows:
The sequence name starts with seq _, followed by the field name of the sequence. If several fields use the same sequence, use an underscore (_) to join the names of several fields. If different tables use different sequences for the same field names, add the table features after the field names and connect them with underscores. The sequence Name Length cannot exceed 30 characters. The sequence name is represented by lowercase English words.
2.6 stored procedures
The naming rules for stored procedures are as follows:
The stored procedure name starts with Pr _. The length of the stored procedure name cannot exceed 30 characters. The stored procedure name is expressed in lowercase.
2.7 Functions
The function naming rules are as follows:
The function name starts with Fu _. The function name cannot exceed 30 characters. The function name is represented by lowercase English words.
2.8 trigger
The trigger naming rules are as follows:
The trigger name starts with Tr _. The trigger name cannot exceed 30 characters. The trigger name is represented by lowercase English words.
2.9 primary key
The primary key naming rules are as follows:
The primary key name starts with pk _, followed by the table name where the primary key is located. The primary key name cannot exceed 30 characters. If it is too long, you can abbreviated the table name. The abbreviation rule is the same as the abbreviation rule of the table name. The primary key name is represented by lowercase English words.
2.10 foreign key
The naming rules for foreign keys are as follows:
The foreign key name starts with fk _, followed by the table name of the foreign key and the corresponding primary table name (excluding t _). The sub-table name and parent table name are separated by underscores. The length of the foreign key name cannot exceed 30 characters. If it is too long, you can abbreviated the table name. The abbreviation rule is the same as the abbreviation rule of the table name. The foreign key name is represented by lowercase English words.
2.11 Index
The index naming rules are as follows:
1) The index name is represented by lowercase English letters and numbers. The index name cannot exceed 30 characters.
2) The index corresponding to the primary key has the same name as the primary key.
3) Each type of index ends.
4) The unique index starts with uni _, followed by the table name. The general index starts with ind _, followed by the table name.
5) if the index length is too long, you can abbreviation the table name. The abbreviation rule is the same as the abbreviation rule of the table name.