Home > Database > SQL > body text

What are the nine commonly used statements in SQL

silencement
Release: 2019-06-15 11:16:42
Original
11948 people have browsed it

What are the nine commonly used statements in SQL

1. Basics
1. Instructions: Create database
CREATE DATABASE database-name
2. Instructions: Delete database
drop database dbname
3. Description: Back up sql server
--- Create a device for backup data
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
- -- Start backup
BACKUP DATABASE pubs TO testBack
4. Instructions: 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 new table
drop table tabname
6. Description: Add a column
Alter table tabname add column col type
Note: Once a column is added, it cannot be deleted. In DB2, the data type cannot be changed after the column is added. The only thing that can be changed is to increase the length of the varchar type.
7. Instructions: Add primary key: Alter table tabname add primary key(col)
Instructions: Delete primary key: Alter table tabname drop primary key(col)
8. Instructions: Create index: create [unique] index idxname on tabname(col….)
Delete index: drop index idxname
Note: The index cannot be changed. If you want to change it, you must delete it and rebuild it.
9. Description: Create a view: create view viewname as select statement
Delete a view: drop view viewname

The above is the detailed content of What are the nine commonly used statements in SQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!