Create (or delete) a database, table

Source: Internet
Author: User

1. Basic statements for creating a database

CREATE DATABASE database_name

* NOTE: database_name is the name of the database you want to create

1.1 Deleting a database statement

DROP DATABASE database_name

2. Create a data table

CREATE TABLE table_name

* NOTE: table_name is the name of the database you want to create

2.1 Delete A statement from a data table

DROP TABLE database_name

Here is an example of a normal point: see the following code:

1Use master--working with System databases2 GO3IF EXISTS (SELECT * from sysdatabases WHERE name=n'Db_mystudentlife')   4DROP DATABASE [Db_mystudentlife]; --if the database to be created exists, delete the5 GO6CREATE DATABASE [Db_mystudentlife]--Create a database7 GO8Use [Db_mystudentlife]--Working with Databases9 GOTenIF EXISTS (SELECT * from sysobjects WHERE name=n'MyClass') OneDROP TABLE [MyClass]--If the data table you want to create exists, delete it (note that the sysobjects must be all lowercase, otherwise there is an error and cannot be written in uppercase.) ) A GO -CREATE TABLE MyClass--Create a data table - ( thec_id INT not NULL PRIMARY KEY IDENTITY (1,1), --class Number -C_name NVARCHAR ( $) notNULL,               --class name -C_DESCR nvarchar (max) notNULL--Class Introduction -   + ); - GO +IF EXISTS (SELECT * from sysobjects WHERE name=n'mystudent') A DROP TABLE mystudent at GO - CREATE TABLE mystudent - ( -s_idintNotNULLPrimary Key Identity (1,1),   --School Number -S_name nvarchar ( -) notNULL,                  --name -S_genderChar(2) notNULL,                     --Sex ins_address nvarchar (max) notNULL,             --Address -S_phone nvarchar ( -) notNULL,                  --Telephone toS_ageintNotNULL,                            --Age +S_birthday datetime notNULL,                  --Birthday -S_cardidintNotNULL,                         --ID Number theS_cidintNotNULLReferences MyClass (c_id)--class Number *  $);

Create (or delete) a database, table

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: 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.