Create DATABASE Studb
On primary--The default is the primary filegroup, which can be omitted
(
/*--description of the data file--*/
Name= ' Studb_data ',--the logical name of the master data file
Filename= ' D:\stuDB_data.mdf ',--the physical name of the master data file
SIZE=5MB,--Initial size of master data file
MAXSIZE=100MB,--Maximum value of master data file growth
filegrowth=15%--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
)
--*********************** constraint sql******************************
Use Studb
Go
if exists (select * from sysobjects where name= ' Stumarks ')
drop table Stumarks
CREATE TABLE St Umarks
(
examno int identity (UP) Primary key,
stuno char (6) NOT NULL,
Writtenexam int NOT NULL,
labexam int NOT NULL
)
Go
--Where the column attribute "identity (start value, increment)" means "Examno" is automatically numbered, also known as the identity column
ALTER TABLE table name
Add constraint constraint name constraint type specific constraint description
ALTER TABLE table name
DROP CONSTRAINT constraint name
ALTER TABLE Stumarks
Add constraint Uq_stuno Unique (Stuno)
ALTER TABLE Stumarks
Drop constraint Uq_stuno
/*--Add SQL Login account--*/
exec sp_addlogin ' Xie ', ' 123456 '--account name Xie, password 123456
--Delete Xie account name
exec sp_droplogin ' Xie '
/*--Add two users (must exist) in the STUDB database--*/
Use Studb
Go
exec sp_grantdbaccess ' Xie ', ' 123456 '
Go
--Hint: the dbo user in SQL Server is the user who has all the active permissions in the database, representing the owner of the database (owner), in general,
-If you create a database that is the owner of the database, the dbo user, the dbo user is a special database user and cannot be deleted, and this
--The user always appears in each database
/*-Authorization to database user--*/
--The syntax for authorization is as follows
--grant permissions [on table name] to database user
Use Studb
Go
Grant Select,update,insert on Stumarks to Xie
Grant CREATE table to Xie
Go
Create database specify path SQL