Original:
Https://www.cnblogs.com/wlx520/p/4684441.html
Library-related build libraries
--Before creating the school database: first to determine whether the database exists, if it is deleted and then created, if it does not exist, create-
--exists keyword: The parentheses inside can query to the data is returned ' true ' otherwise return ' false '
if exists (SELECT * from sysdatabases where name = ' School ')
--exists returns ' true ' to perform the delete database operation--
Drop Database School
--exists returns ' false ' to indicate that the database does not exist and is created directly
Create DATABASE School
On primary
(
--Master database file--
name = ' School ',--main data file logical name
filename = ' D:\project\School.mdf ',--master data file physical logical name
Size = 5MB,--Initial value
MaxSize = 100MB,--Maximum size
filegrowth = 15%--Data File growth
)
Log on
(
--Log file--
name = ' School_log ',
filename = ' D:\project\School_log.ldf ',
Size = 2MB,
FileGrowth = 1MB
)
Go
See which libraries are available
SELECT * FROM sysdatabases
Delete a library
Drop Database School
Table Related CREATE TABLE
--1, select the operational database--
Use School
Go
--Judging whether the table exists--
if exists (select * from sysobjects where name = ' Student ')
drop table Student
--2, creating Tables---
CREATE TABLE Student
(
--specific column name data type column characteristics (whether empty)--
Studentno int Identity (2,1) is not NULL,
Loginpwd nvarchar () NOT NULL,
Studentname nvarchar () NOT NULL,
Sex int NOT NULL,
Gradeid int NOT NULL,
Phone nvarchar () NOT NULL,
Borndate datetime NOT NULL,
Address nvarchar (255),
Email nvarchar (50),
Identitycard varchar (18)
)
Go
See what tables are available
---View all database objects (database tables)---
SELECT * from sysobjects
Writing table Data
INSERT into student (name) VALUES (' s1 ');
Delete a table
drop table Student
SQL Server Library related-table related-3