SQL Server Library related-table related-3

Source: Internet
Author: User

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

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: info-contact@alibabacloud.com 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.