如何以编程方式创建表

编程入门 行业动态 更新时间:2024-10-08 10:58:17
本文介绍了如何以编程方式创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要通过以编程方式读取现有数据库来创建重复数据库及其表和约束. 我已经以编程方式创建了数据库.但是我需要按特定顺序创建这些表.在我现有的数据库中,有很多相关的表.因此,我需要先创建父表,然后再创建其子表. 假设数据库DB1中有2个表"Table1"和"Table2". 假设Table2是Table1的父级.那就是使用外键的Table1,外键是Table2的主键. 因此,我需要首先创建Table2.但是当我使用时

Hi, I need to create a duplicate database and its tables and constraints by reading from an existing database programmatically. I have created the database programmatically. But I need to create those tables in a particular order. In my existing database there are lots of related tables.So I need to create parent table first, then its child tables. Suppose 2 tables "Table1" and "Table2" in database DB1. Suppose Table2 is the parent of Table1. That is Table1 using a foreign key which is the primary key of Table2. So I need to create Table2 first. But while I am using

Database objDatabase = objServer.Databases["DB2"];

然后遍历objDatabase.tables我得到了Table1,Table2的订单 这是我的问题.请帮帮我 预先感谢.

And looping through objDatabase.tables I am getting the order Table1, Table2 This is my problem. Please help me Thanks in advance.

推荐答案

hi 试试这个 创建表之前,请先进行如下验证: hi try this before creating table validate like this string validate="SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE=''BASE TABLE'' AND TABLE_NAME=''" + tablename + "_GroupMaster''"; after validate like this to create string s= "create table " + tablename + "_GroupMaster(Slno int identity(1,1),GroupId Char(7) null,GroupName varchar(150) null,Status Char(1) null,MasterId notnull)";

更多推荐

如何以编程方式创建表

本文发布于:2023-11-28 11:17:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!