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