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

jieshen 2004-05-02 08:59:21
小弟用的是vs的asp.net开外一个网站,我想在网页上添加一个功能----可以对数据库进行操作(数据库是mssql2000)可以新建一张表。不知道用的是什么语句??
...全文
105 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangsuipeng 2004-05-03
  • 打赏
  • 举报
回复
顶吧
hivak47 2004-05-03
  • 打赏
  • 举报
回复
wangsaokui(无间道II(前传)) 写的挺详细的。
sukey00 2004-05-03
  • 打赏
  • 举报
回复
你在sql中手工建了表后,用脚本就能看到建表的语句了
taosihai1only 2004-05-03
  • 打赏
  • 举报
回复
Create Table 表名 (字段1 字段类型,字段2 字段类型,...)
michaelowenii 2004-05-03
  • 打赏
  • 举报
回复
Create Table 表名 (字段1 字段类型,字段2 字段类型,...)
wolftop 2004-05-03
  • 打赏
  • 举报
回复
UP!~UP!~UP!~
smx717616 2004-05-02
  • 打赏
  • 举报
回复
呵呵,来晚了
whalefish2001 2004-05-02
  • 打赏
  • 举报
回复
Create Table 表名 (字段1 字段类型,字段2 字段类型,...)
terran731 2004-05-02
  • 打赏
  • 举报
回复
你在sql中手工建了表后,用脚本就能看到建表的语句了
wangsaokui 2004-05-02
  • 打赏
  • 举报
回复
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运行,如果是其他用户,要设定建表的权限
tornadozhang 2004-05-02
  • 打赏
  • 举报
回复
Create Table 表名 (字段1 字段类型,字段2 字段类型,...)
lansluo 2004-05-02
  • 打赏
  • 举报
回复
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();
}

最好适用存储过程来做,在程序里写,语句在串接的时候很容易出错。

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧