Database design:
Three-paradigm (old)
Column values are unique and cannot have duplicate column values
property is completely dependent on the primary key
Must meet the first paradigm
Must have a primary key
The other columns must be fully dependent on the primary key
property is not dependent on other non-primary properties (second enhancement)
Must satisfy the second paradigm
Removal of transitive dependencies
(In a specific case, the efficiency of the consideration, such as: specifically to do redundancy, do not adhere to the third)
Oracle sequence
A sequence can be used to generate a primary key for a single table service, or multiple
Create a sequence
Create sequence sequence name start with numeric Incremet by value
| Do not write is 1 |
Delete a sequence
Drop Sequence sequence Name
Get the next value from a pseudo-column nextval
Select Seq_stu.nextval from dual;
Gets the current value Currval
Select Seq_stu.currval from dual;
Create sequence Seq_stu start with Incremet by5;select seq_stu.nextval from Dual;insert to Stu (ID) VALUES (SEQ_STU.N Extval);
Complete:
CREATE TABLE Stu (s_id number, s_name varchar2 (), Constraint S_PK primary key (s_id)) Create sequence Seq_stu start With + increment by 5;select * from Stu;
Package Jdbc;public class Stu {private int id;private String name;public int getId () {return ID;} public void setId (int id) {this.id = ID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;}}
package jdbc;import java.sql.connection;import Java.sql.preparedstatement;public class studao {private static final string SQL = "Insert into stu (s_id,s_name) values (Seq_stu.nextval,?)"; Public void save (Stu stu) throws exception{connection con = null;try{ Con = dbutils.getconnection (); Preparedstatement stmt = con.preparestatement (SQL); Stmt.setstring (1,stu.getname ()); Stmt.executeupdate ();} catch (exception e) {throw e;} Finally{if (con != null) {con.close ();}}}}
Package Jdbc;import static Org.junit.assert.*;import Org.junit.test;public class Teststudao {@Testpublic void Test () Throws Exception {Studao s = new Studao (); Stu ss = new Stu (); Ss.setname ("Lmdtx"); S.save (ss);}}
er Diagram (open source community has the truth)
Find what you like or what your company is used to (tools) A4 paper
Research business needs
Designing and drawing E-r diagrams
Design document
Write what you need to write.
This article is from the "Romantic Laugh" blog, make sure to keep this source http://lmdtx.blog.51cto.com/6942028/1840339
JAVA41: Database Five (Oracle)