在不打开sql server 2005的情况下在sql server中创建表 [英] Creating Table in sql server without opening sql server 2005

查看:69
本文介绍了在不打开sql server 2005的情况下在sql server中创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向所有人问好,

我的问题是我们可以在不打开sqlserver 2005的情况下创建sql表吗?
我想使用ASP.NET 3.5使用C#代码创建表(如果可能).

解决方案

是的,您可以在不打开SqlServer的情况下创建SQL表.

您应该在C#代码中使用Create Table语句.

using (SqlConnection con = new SqlConnection(yourConnectionStringHere)) //put your connection string here
{
con.Open();
try
{
    using (SqlCommand command = new SqlCommand(
    "CREATE TABLE Dogs1 (Weight INT, Name TEXT, Breed TEXT)", con))
    {
    command.ExecuteNonQuery();
    }
}
catch
{
    Console.WriteLine("Table couldn''t be created.");
}
}



参考: http://www.dotnetperls.com/sqlclient [ (``col1''``datatype1''``null/not null'',
``col2''``datatype2''``null/not null'',
``col3''``datatype3''``null/not null'',
)

请记住,这是一个非常基本的查询,您可能必须根据需要对其进行修改.您(运行应用程序的帐户)还应该具有在数据库上创建表的权限.


Hy To All,

My question is can we create a sql table without opening sqlserver 2005

i want to use ASP.NET 3.5 using C# code for creating the tables if this possible.

Yes, You can create SQL table without opening SqlServer.


You should use Create Table statement in your C# code.

using (SqlConnection con = new SqlConnection(yourConnectionStringHere)) //put your connection string here
{
con.Open();
try
{
    using (SqlCommand command = new SqlCommand(
    "CREATE TABLE Dogs1 (Weight INT, Name TEXT, Breed TEXT)", con))
    {
    command.ExecuteNonQuery();
    }
}
catch
{
    Console.WriteLine("Table couldn''t be created.");
}
}



Ref:
http://www.dotnetperls.com/sqlclient[^]


I believe you don''t want to use SSMS (Management Studio). Suggest you run below query (as command) through your application:

create table ''table name''
(''col1'' ''datatype1'' ''null/not null'',
''col2'' ''datatype2'' ''null/not null'',
''col3'' ''datatype3'' ''null/not null'',
)

Remember this is a very basic query, you might have to modify it to your needs. ALSO you (the account under which your application is running) should have permissions to create table on the DB.


这篇关于在不打开sql server 2005的情况下在sql server中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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