tailieunhanh - Adding Tables to a Database

[ Team LiB ] Recipe Adding Tables to a Database Problem You need to add a table to an existing database. Solution Use the CREATE TABLE statement. The sample code executes the DDL statement—using the ExecuteNonQuery( ) method of the Command object—to add a table to an existing SQL Server database. | Team LiB Recipe Adding Tables to a Database Problem You need to add a table to an existing database. Solution Use the CREATE TABLE statement. The sample code executes the DDL statement using the ExecuteNonQuery method of the Command object to add a table to an existing SQL Server database. The C code is shown in Example 10-8. Example 10-8. File Namespaces variables and constants using System using using using . . . SqlConnection conn new SqlConnection Sql_ConnectString String createSql CREATE TABLE MyTable MyTableld int IDENTITY 1 1 PRIMARY KEY CLUSTERED SqlCommand cmd new SqlCommand createSql conn Create the table in the database. try Table created successfully catch ex finally if Discussion There are two categories of SQL statements Database Definition Language DDL Used to manage all objects in the database generally with CREATE ALTER and DROP statements to create modify and delete objects respectively. These statements generally require DBA permissions to execute. Database Management Language DML Used to manipulate select insert update and delete data in the database objects. Database objects are defined using DDL. The solution executes a DDL CREATE TABLE statement to create a table in the database and a primary key on the new table in a SQL Server database. You can programmatically drop a table using the DROP TABLE statement in a similar way. To drop the table created in this example use the following code DROP TABLE MyTable The DROP TABLE statement will fail if the table is in use therefore it might be necessary to restart the SQL Server. For more information about the CREATE TABLE statement or the DROP TABLE statement see Microsoft SQL Server Books Online. The solution for Oracle databases and other .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.