由於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