sql server如何根据已有表创建新表
A:createtabletab_newliketab_old(使用旧表创建新表)B:createtabletab_newasselectcol1,col2…fromta...
A:create table tab_new like tab_old (使用旧表创建新表)
B:create table tab_new as select col1,col2… from tab_old definition only 展开
B:create table tab_new as select col1,col2… from tab_old definition only 展开
2个回答
展开全部
可以用 ADO.NET 写出并执行 T-SQL 语句来创建表:
private void CreateTableBtn_Click(object sender, System.EventArgs e)
{
// 打开连接
if (conn.State == ConnectionState.Open)
conn.Close();
ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=mydb;" +
"Data Source=localhost;";
conn.ConnectionString = ConnectionString;
conn.Open();
sql = "CREATE TABLE myTable" +
"(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," +
"myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)";
cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
private void CreateTableBtn_Click(object sender, System.EventArgs e)
{
// 打开连接
if (conn.State == ConnectionState.Open)
conn.Close();
ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=mydb;" +
"Data Source=localhost;";
conn.ConnectionString = ConnectionString;
conn.Open();
sql = "CREATE TABLE myTable" +
"(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," +
"myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)";
cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询