Create database specify path SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.