string sqlStr=@"CREATE TABLE [dbo].[tbTest](
[id] [int] IDENTITY(1,1) NOT NULL,
[information] [varchar](100) NULL,
primary key(id)
)";ExecuteSql(sqlStr);
public static int ExecuteSql(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.SqlClient.SqlException e)
{
connection.Close();
throw e;
}
}
}
}
[id] [int] IDENTITY(1,1) NOT NULL,
[information] [varchar](100) NULL,
primary key(id)
)";ExecuteSql(sqlStr);
public static int ExecuteSql(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.SqlClient.SqlException e)
{
connection.Close();
throw e;
}
}
}
}
(
[ID] int IDENTITY(1,1) NOT NULL,
[information] nvarchar(100),
[Name] nvarchar(50),
CONSTRAINT [PK_表名] PRIMARY KEY CLUSTERED ([ID] ASC)
)
(
[ID] int IDENTITY(1,1) NOT NULL,
[information] nvarchar(100),
[Name] nvarchar(50),
CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED ([ID] ASC)
)insert into test(information,Name) values('aaaa','shenzhen')
insert into test(information,Name) values('bbb','shanghai')
insert into test(information,Name) values('ccc','beijing')select * from test/*
ID information Name
1 aaaa shenzhen
2 bbb shanghai
3 ccc beijing
*/