SQL database and Datasheet Action statement

Source: Internet
Author: User
Tags create database

SQL database tutorial and Datasheet Action statement
This includes database creation, deletion, modification, backup, and data table new table, delete table, add Table index, create VIEW, etc.
1, Description: Create a database
Create DATABASE Database-name
2, Note: Delete the database
Drop Database dbname
3, Description: Backup SQL Server
Device to create 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],..)
To create a new table from an existing table:
A:create table tab_new like Tab_old (Create a new table using the old table)
B:create table tab_new as Select Col1,col2 ... from tab_old definition only
5, Description: Delete the new table
drop table TabName
6. Description: Add a column
ALTER TABLE tabname add column col type
Note: The column will not be deleted after it has increased. The data type can not be changed when the column in the DB2 is added, and the only change is the length of the varchar type.
7. Description: Add PRIMARY key: ALTER TABLE TabName add primary key (COL)
Description: Delete primary key: ALTER TABLE tabname drop PRIMARY key (COL)
8. Description: Creating index: Create [unique] index idxname on tabname (col ...)
Deleting indexes: Drop INDEX Idxname
Note: The index is not to be changed and you want to change the rebuild must be deleted.
9. Description: Create VIEW: Created view viewname as SELECT statement
Delete view: Drop View ViewName

The above 9 statements are you learn the database must know oh, are basic and commonly used some 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.