SQL database and data table operation statements

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.