Huang Cong: codesmith and powerdesigner installation and database creation (original series tutorial)

Source: Internet
Author: User
Tags microsoft sql server 2005 powerdesigner

I have to take a short exam recently, but I still decided to leave it empty every day to write the codesmith series.ArticleI am afraid to use the word "tutorial" here. After all, I don't know much about codesmith, and many cool people have published many articles about codesmith in the blog garden, however, I still want to share my experiences and hope to give more reference to beginners. If there are errors or unclear descriptions in the tutorial, you are welcome to point out that I will continue to stick to the previous style, use as many pictures as possible to illustrate the steps, because I think it is easier to understand the text.

Well, let's talk about it. Let's start our codesmith journey. let's first talk about the goals of this series of tutorials. As we all know, one of the powerful functions of codesmith is to generate batch data based on templates.CodeThis is why it attracts many programmers to use it. It greatly saves programming time and saves a lot of copy and paste waste operations.

First of all, since we want to explain how to use codesmith and powerdesigner to quickly generate batch code, of course we need to install the two software first. Let's briefly talk about how to install and crack the two software, of course, cracking is only a learning purpose. Please do not use it for commercial purposes. You must support genuine products. Everyone is engaged in software and it is difficult to develop a set of software.

Codesmith installation method:

1) Click to download the Installation File
2). Run the command and leave the installation steps empty. Select the directory you want to install and click "Next.
3). Run, Select the codesmith installation directoryTo crack the attack.
Now, you can start running the program -- codesmith professional 5.1 -- codesmith studio.

Powerdesigner installation method:
Http://dev.firnow.com/course/3_program/java/javajs/20090908/174375.html

After the two software are installed, let's start using them. As before, we need to put forward the requirements and then use the instances, because we use them, it must be because they can cleverly solve a certain problem, or we will spend so much time and hard disk space to install them.

Well, our current requirement is: we hope that when we receive a new project,ProgramYou only need to design the database structure (table, table field, and relationship between tables) according to the project requirements.One buttonTo immediately obtain allHierarchical Architecture code file. That is to say,We hope to get all the code we want without having to knock a line of code.! This is what the two software can do, and it is also our purpose to install them.

Now, the roles have been introduced. Let's see how they perform the wonderful performances:

First, we need to create a test database. For simplicity, we only need to create oneStudentTableAnd oneMajorTableThe table structure and relationship are as follows.

Let's see how to use powerdesigner to quickly create this database.

1. Start to use powerdesigner to create a database. First run the program and enter the main interface:

2. File-New Model-physical data model-physical dimo-- model nameSetTest, DBMS attribute is setMicrosoft SQL Server 2005:

3. Create a table template using the table tool:

4. Double-click a table template to set properties. First, SetMajorTable:

5. Set the table name and clickColumnsLabel, set field properties, set:

6. Because the majorid field is setAutomatic GrowthTo set its advanced attributes, select the majorid field, click Properties, and select the "Identity" check box on the General Panel:

7. After confirming, create another student table and set the fields:

8. create a foreign key majorid for student. You can use powerdesigner to easily complete this task. Select the link setting tool, hold down the left button on the student table, and drag it to the major table, you can add a foreign key of majorid to the student table:

9. Haha, now that the test table has been set up, set the database we want to generate. All these tables will be created in the database. We will go to the blank area of the design panel.Right-click-PropertiesIn the pop-up attribute Settings dialog box, set as follows:

 

10. Here we have completed the settings for the new database, but it is still blank in SQL. How can we port the structure designed here to sqlserver 2005? Perform the following operations:Database-generate Database, Set the export directory and file name for the stored procedure, and click OK:

11. Go to your export directory and you will see the exported database creation and storage process. Open the SQL statement and execute it. Then you will see that the database has been created magically:

12. Now, the database preparation is complete. In the next article, we will use the database and codesmith to automatically generate code in batches ~

TheSource code:

SQL. SQL

/* ========================================================== ====================================== */
/* Database Name: pd_test */
/* DBMS name: Microsoft SQL Server 2005 */
/* Created on: 17:27:17 on Sunday */
/* ========================================================== ====================================== */

DropDatabasePd_test
Go

/* =================================================== ========================================== */
/* Database: pd_test */
/* =================================================== ========================================== */
Create database pd_test
go

UsePd_test
Go

/* ========================================================== ====================================== */
/* Table: Major */
/* ========================================================== ====================================== */
Create Table Major (
Majorid Int Identity ,
Name Nvarchar ( 20 ) Not Null ,
Remark Nvarchar ( Max ) Null ,
Constraint Pk_major Primary Key (Majorid)
)
Go

/* ========================================================== ====================================== */
/* Table: Student */
/* ========================================================== ====================================== */
Create Table Student (
Studentid Nvarchar ( 20 ) Not Null ,
Majorid Int Null ,
Name Nvarchar ( 20 ) Not Null ,
Sex Bit Not Null ,
Age Int Null ,
Remark Nvarchar ( Max ) Null ,
Constraint Pk_student Primary Key (Studentid)
)
Go

alter table Student
Add constraint fk_student_reference_major Foreign key (majorid)
references major (majorid)
go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.