CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

用什么的语句可以新建一张表?

楼主jieshen(吃"食"大仙)2004-05-02 08:59:21 在 .NET技术 / ASP.NET 提问

小弟用的是vs的asp.net开外一个网站,我想在网页上添加一个功能----可以对数据库进行操作(数据库是mssql2000)可以新建一张表。不知道用的是什么语句?? 问题点数:100、回复次数:12Top

1 楼lansluo(最后一个女巫)回复于 2004-05-02 09:15:22 得分 60

SqlConnection   con   =   new   SqlConnection("server=150.0.1.200;user=sa;password=sa;database=test");  
  string   sql   =   "Create   Table   testtable(test1   varchar   not   null   primary   key,test2   int)";  
  SqlCommand   cmd   =   new   SqlCommand(sql,con);  
  cmd.Connection.Open();  
  try  
  {  
  cmd.ExecuteNonQuery();  
  }  
  catch(Exception   ex){MessageBox.Show(ex.Message);}  
  finally  
  {  
  cmd.Connection.Close();  
  }  
   
  最好适用存储过程来做,在程序里写,语句在串接的时候很容易出错。Top

2 楼tornadozhang(zhang)回复于 2004-05-02 09:15:46 得分 5

Create   Table   表名   (字段1   字段类型,字段2   字段类型,...)Top

3 楼wangsaokui(无间道III(终极无间)C#MVP)回复于 2004-05-02 09:25:37 得分 30

CREATE   TABLE  
  Creates   a   new   table.  
   
  Syntax  
  CREATE   TABLE    
          [   database_name.[   owner   ]   .   |   owner.   ]   table_name    
          (   {   <   column_definition   >    
                  |   column_name   AS   computed_column_expression    
                  |   <   table_constraint   >   ::=   [   CONSTRAINT   constraint_name   ]   }  
   
                          |   [   {   PRIMARY   KEY   |   UNIQUE   }   [   ,...n   ]    
          )    
   
  F.   Complete   table   definitions  
  This   example   shows   complete   table   definitions   with   all   constraint   definitions   for   three   tables   (jobs,   employee,   and   publishers)   created   in   the   pubs   database.  
   
  举例  
   
  /*   **************************   jobs   table   **************************   */  
  CREATE   TABLE   jobs  
  (  
        job_id     smallint  
              IDENTITY(1,1)  
              PRIMARY   KEY   CLUSTERED,  
        job_desc                 varchar(50)           NOT   NULL  
              DEFAULT   'New   Position   -   title   not   formalized   yet',  
        min_lvl   tinyint   NOT   NULL  
              CHECK   (min_lvl   >=   10),  
        max_lvl   tinyint   NOT   NULL  
              CHECK   (max_lvl   <=   250)  
  )  
   
  /*   *************************   employee   table   *************************   */  
  CREATE   TABLE   employee    
  (  
        emp_id     empid  
              CONSTRAINT   PK_emp_id   PRIMARY   KEY   NONCLUSTERED  
              CONSTRAINT   CK_emp_id   CHECK   (emp_id   LIKE    
                    '[A-Z][A-Z][A-Z][1-9][0-9][0-9][0-9][0-9][FM]'   or  
                    emp_id   LIKE   '[A-Z]-[A-Z][1-9][0-9][0-9][0-9][0-9][FM]'),  
              /*   Each   employee   ID   consists   of   three   characters   that    
              represent   the   employee's   initials,   followed   by   a   five    
              digit   number   ranging   from   10000   through   99999   and   then   the    
              employee's   gender   (M   or   F).   A   (hyphen)   -   is   acceptable    
              for   the   middle   initial.   */  
        fname       varchar(20)           NOT   NULL,  
        minit       char(1)   NULL,  
        lname       varchar(30)           NOT   NULL,  
        job_id     smallint                 NOT   NULL  
              DEFAULT   1  
              /*   Entry   job_id   for   new   hires.   */  
              REFERENCES   jobs(job_id),  
        job_lvl   tinyint  
              DEFAULT   10,  
              /*   Entry   job_lvl   for   new   hires.   */  
        pub_id     char(4)   NOT   NULL  
              DEFAULT   ('9952')  
              REFERENCES   publishers(pub_id),  
              /*   By   default,   the   Parent   Company   Publisher   is   the   company  
              to   whom   each   employee   reports.   */  
        hire_date               datetime                 NOT   NULL  
              DEFAULT   (getdate())  
              /*   By   default,   the   current   system   date   is   entered.   */  
  )  
   
  参照一楼,当个SqlCommand运行,如果是其他用户,要设定建表的权限Top

4 楼whalefish2001(whale)回复于 2004-05-02 10:28:49 得分 5

Create   Table   表名   (字段1   字段类型,字段2   字段类型,...)  
  Top

5 楼smx717616(又笨又不努力)回复于 2004-05-02 10:36:37 得分 0

呵呵,来晚了Top

6 楼terran731(基层干部)回复于 2004-05-02 21:49:28 得分 0

你在sql中手工建了表后,用脚本就能看到建表的语句了Top

7 楼lijun84(李俊俊)回复于 2004-05-03 01:58:43 得分 0

UP!~UP!~UP!~Top

8 楼michaelowenii(少年狂)回复于 2004-05-03 20:24:52 得分 0

Create   Table   表名   (字段1   字段类型,字段2   字段类型,...)  
  Top

9 楼taosihai1only(无招胜有招)回复于 2004-05-03 20:41:27 得分 0

Create   Table   表名   (字段1   字段类型,字段2   字段类型,...)Top

10 楼sukey00(怕怕.Web)回复于 2004-05-03 22:00:26 得分 0

你在sql中手工建了表后,用脚本就能看到建表的语句了  
  Top

11 楼hivak47(比尔)回复于 2004-05-03 23:14:54 得分 0

wangsaokui(无间道II(前传))   写的挺详细的。Top

12 楼huangsuipeng(hsp|I love foxpig)回复于 2004-05-03 23:23:48 得分 0

顶吧Top

相关问题

  • 帮我写一条新建表的语句,很简单。
  • sql语句请教(两张表)
  • 怎样使用已有表中的所有字段重新建一个新表,sql语句如何写?
  • 怎样在paradox里写一个新建表的SQL语句,最好是所有类型都用上的
  • 怎样把select语句选出来的记录放到另一个新建的表中?
  • 如何用join ... on语句查询三张表
  • 如何让两条sql语句在同一张表中显示
  • 用VB在Access2000里建一张表的语句怎么写?
  • sql语句的问题:left join 可以连接多张表吗?
  • 这个关联两张表的sql语句该怎么写?

关键词

  • 语句
  • 字段
  • database
  • null
  • 表
  • lvl
  • job
  • constraint
  • cmd
  • primary key

得分解答快速导航

  • 帖主:jieshen
  • lansluo
  • tornadozhang
  • wangsaokui
  • whalefish2001

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo