The SQL and data table operation statements include creating, deleting, modifying, and backing up databases, creating, deleting tables, adding table indexes, and creating views. 1. Description: create Database createdatabasedatabase-name2, Description: delete database dropdatabasedbname3, Description: Backup sqlserver --- create backup data deviceusemasterexecsp_a SQL and data table operation statement
This section describes how to create, delete, modify, and back up databases, create tables for data tables, Delete tables, Add Table indexes, and create views;
1. Description: Create a database
Create database-name
2. Description: delete a database.
Drop database dbname
3. Description: Back up SQL server
--- Create a device for the backup data
Use master
Exec sp_addumpdevice 'disk', 'testback', 'c: www.111cn. netmynwind_1.dat'
--- Start backup
Backup database pubs to testback
4. Description: Create a new table.
Create table tabname (col1 type1 [not null] [primary key], col2 type2 [not null],...)
Create a new table based on an existing table:
A: create table tab_new like tab_old (use the old table to create a new table)
B: create table tab_new as select col1, col2... From tab_old definition only
5. Description: delete a new table.
Drop table tabname
6. Description: Add a column.
Alter table tabname add column col type
Note: Columns cannot be deleted after they are added. After columns are added to db2, the data type cannot be changed. The only change is to increase the length of the varchar type.
7. Description: add a primary key: alter table tabname add primary key (col)
Delete a primary key: alter table tabname drop primary key (col)
8. Description: create an index: create [unique] index idxname on tabname (col ....)
Delete index: drop index idxname
Note: The index cannot be changed. To change the index, you must delete it and recreate it.
9. Description: create view viewname as select statement
Delete view: drop view viewname
The nine statements above are required for database learning. They are basic and commonly used operations.