To create the SQL statement for the database:
CREATE DATABASE Studb on primary--by default it belongs to the primary filegroup, which can be omitted (/*-- specific description of the data file--*/name='Studb_data', --logical name of the master data file filename='D:\stuDB_data.mdf', --physical name of the master data file size=5MB,--Initial size of master data file MaxSize=100MB,--maximum number of main data file growth filegrowth= the%--the growth rate of the master data file) log on (/*--The specific description of the log file, the meaning of each parameter ibid .*/name='Studb_log', filename='D:\stuDB_log.ldf', size=2MB, FileGrowth=1MB)
So how do you delete this database, SQL Server stores the list of databases in the sysdatabases table of the Master System database, and only needs to see if the table exists in that database.
, with the following statement:
Use master-- set the current database as master to access the sysdatabases table goif exists (selectfromwhere name='studb') drop database Studbgo
The SQL statements that create the table and delete the table are as follows:
Use studbgoifExistsSelect* fromsysobjectswhereName='Stumarks') drop table stumarkscreate table Stumarks (ExamnointIdentity1,1) primary key, StunoChar(6) notNULL, WrittenexamintNotNULL, LabexamintNotNULL) Go--Where the column properties"identity (start value, increment amount)"Said"Examno"listed as AutoNumber, also known as identity column ALTER TABLE name ADD CONSTRAINT constraint name constraint type specific constraint description ALTER TABLE table name DROP CONSTRAINT constraint name ALTER TABLE Stumarksadd CO Nstraint Uq_stuno Unique (stuno) ALTER TABLE Stumarksdrop constraint Uq_stuno/*-- Add SQL login account--*/EXEC sp_addlogin'Xie','123456'--The account name is Xie and the password is 123456--Delete Xie account name exec sp_droplogin'Xie'/*-- Add two users to the STUDB database (must exist)--*/Use studbgo exec sp_grantdbaccess'Xie','123456'Go--tip: The dbo user in SQL Server is a user who has all the active permissions in the database, representing the owner of the database (owner), generally speaking,--If you create a database that is the owner of the database, that is, the dbo user, the dbo user is a special database user and cannot be deleted, and this--the user is always present in each database/*-- authorization to the database user--*/--The syntax for authorization is as follows--grant permissions [on table name] to database user use STUDBGO GrantSelect, Update,insert on Stumarks to Xie Grant create table to Xiego
Creating SQL statements for databases and tables