从代码创建表和字段 [英] Creating Tables and Fields from Code

查看:60
本文介绍了从代码创建表和字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是初学者.net开发,请帮助



我是使用c#和Vb.Net,visual studio 2010和.net framework 4.0开发windows表单应用程序。

我使用Microsoft SQL Server 2008作为我的数据库。



虽然,我是C#编程的新手,我创建了三层(APP,BLL,DAL)。



现在,

我的项目正在增长,我经常创建表格和字段。目前我正在使用SQL(通过使用create table)。但是,我觉得这不是正确的方法。



所以,

任何人都可以教我跟进



1)如何通过代码创建数据库,表和字段(示例代码会有所帮助)

2)是否可以创建关系表? 。意味着OITM和ITM1是Header和Child表,其中DocEntry是主键吗?

3)在开发项目时保持数据结构的最佳实践是什么?



谢谢和问候

MG

Hi All,

I am beginner to .net Development,Please Help

I am developing windows form application by using c# and Vb.Net,visual studio 2010 and .net framework 4.0.
I am using Microsoft SQL Server 2008 as my database.

though,I am new to C# programming , I've created three layer (APP,BLL,DAL).

Now,
my project is growing and regularly I am creating tables and fields. currently I am doing in SQL(by using create table). but , I feel this is not right way to do.

So,
Can anyone please educate me about following

1) How to create Database,Tables and Fields through Code (sample code would be helpful)
2) is it possible to create relational tables ? . Means OITM and ITM1 are Header and Child table where DocEntry is Primary key ?
3) What are the Best practice to maintain data structure, while developing the project?

Thanks and Regards
M G

推荐答案

直接在数据库中创建表和字段没有错。

通过代码创建新的表或字段更难维护,因为每次添加新列时都必须编译代码。



但是,如果你想要通过代码创建表,尝试创建,修改和删除外键 [< a href =https://msdn.microsoft.com/en-us/library/ms162566.aspxtarget =_ blanktitle =New Window> ^ ]。
There is nothing wrong in creating tables and fields directly in the database.
Creating new tables or fields via code is harder to maintain as you have to compile code everytime a new column is added.

However, if you do want to create tables through code, try Creating, Altering, and Removing Foreign Keys[^].


这篇关于从代码创建表和字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆