由于sqlserver用起来很不爽 可以尝试用vscode+sqlserver插件玩玩
友情提示 在vscode中新建一个.sql 并配置好与sqlserver的连接 利用sql会有提示创建表 数据库等 爽歪歪 右键选择最下面的执行query 
-- Create a new database called \'DatabaseName\'
-- Connect to the \'master\' database to run this snippet
-- USE master
-- GO
-- Create the new database if it does not exist already
-- 只是用来学习用的 具体细节自己加
CREATE DATABASE myfirestdata1010
on PRIMARY
(
    name = \'myfirestdata1010\',
    FILENAME = \'E:\SQL Data\myfirestdata1010.mdf\'
)
log ON
(
    name = \'myfirestdata1010_log\',
    FILENAME = \'E:\SQL Data\myfirestdata1010_log.ldf\'
)
GO

-- Create a new table called \'TableName\' in schema \'SchemaName\'
-- Drop the table if it already exists
-- IF OBJECT_ID(\'myfirestdata1010.students\', \'U\') IS NOT NULL
-- DROP TABLE myfirestdata1010.students
-- GO

USE myfirestdata1010;

-- DROP TABLE students;
-- Create the table in the specified schema
CREATE TABLE students
(
    stu_id INT PRIMARY key,
    stu_name VARCHAR(50) NOT NULL,
    stu_age INT NOT NULL CHECK(stu_age BETWEEN 16 and 22), 
    stu_sex CHAR(2) NOT NULL DEFAULT(\'\') CHECK (stu_sex=\'\' or stu_sex=\'\'),
    stu_address VARCHAR(50) NOT NULL,
    stu_email VARCHAR(50) NOT NULL CHECK (stu_email like \'_%@_%.__%\') UNIQUE
);
GO

-- DROP TABLE scoreInfo;

CREATE TABLE scoreInfo(
    score_id int PRIMARY KEY IDENTITY(1000,1),
    stu_id int FOREIGN KEY REFERENCES students(stu_id),
    score int NOT NULL
)
GO

 

版权声明:本文为my-ordinary原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/my-ordinary/p/11646570.html