Data type
Create a data table
GrammarCREATE TABLETable name (field name 1 data type column attribute column constraint, field name 2 data type column attribute column constraint, field name 3 data type column attribute column constraint,...) Format of column properties:[null| Not NULL] [Identity (Identity seed, identity increment)]format of the column constraint:[CONSTRAINT Constraint name] PRIMARY KEY[(column name)][CONSTRAINT Constraint name] UNIQUE [(column name)][CONSTRAINT Constraint name] [Foreigen key[(Foreign key column)]]REFERENCESprimary table name (Reference column)[CONSTRAINT Constraint name] CHECK(check an expression)[CONSTRAINT Constraint name] DEFAULTDefault Value UseBooksmanagerGo/*Create an author table*/Create TableAuthors (Authoridint not NULL,--numberingAuthorNamenvarchar( +) not NULL,--Author's nameSexbit not NULL,--SexBirthdaydatetime NULL,--BirthdayEmailnvarchar( -),--e-MailTelphonenvarchar( -),--Contact PhoneCitynvarchar( -),--City of ResidenceDescriptionntext–-author profile) UseBooksmanagerGo/*Create an author table*/Create TableAuthors (Authoridint not NULL Identity(1,1)PRIMARY KEY,--numberingAuthorNamenvarchar( +) not NULL,--Author's nameSexbit not NULL DEFAULT 1,--SexBirthdaydatetime NULL,--BirthdayEmailnvarchar( -)DEFAULT '[email protected] ' CHECK (email like'%@%'),--e-mail telphone nvarchar (60),--Contact phone City nvarchar (+) DEFAULT'Beijing',--Description ntext–-, City of residence, introduction to the author)
Determine if a data table exists
Each database has a system table sysobjects, which stores all the data tables, constraints and other information in this database.
Use Booksmanager GO /* detect if a students table exists */ IF EXISTS (SELECT* from WHERE Name=' Authors') DROP TABLE Authors
Deleting a database
DROP table name [, ... n]
Drop Table Authors
DROP TABLE statement cannot delete system tables
If a table is referenced by another table through a FOREIGN key constraint, you must first delete the table that has the FOREIGN KEY constraint set, or delete the external key constraint
Database Management Data Sheet Management (1)