sqlserver命令创建数据库和表 demo
由于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
作者:以罗伊
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。